-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
200 lines (163 loc) · 5.53 KB
/
build.gradle
File metadata and controls
200 lines (163 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
// Lint the code
id 'checkstyle'
// Publish utils
id 'maven'
id 'signing'
}
group = GROUP
version = VERSION_NAME
dependencies {
// Google HTTP library + jackson2 for JSON parsing
compile 'com.google.http-client:google-http-client:1.25.0'
compile 'com.google.http-client:google-http-client-jackson2:1.25.0'
// Javax JSON util
testImplementation 'javax.json:javax.json-api:1.0'
testImplementation 'org.glassfish:javax.json:1.0'
// JUnit test framework
testImplementation 'junit:junit:4.13.1'
}
repositories {
jcenter()
mavenCentral()
}
checkstyle {
toolVersion = '8.12'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" << "-Xlint:-options" << "-Xlint:-processing" << "-Xlint:-serial"
options.encoding = 'UTF-8'
}
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
classifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}
artifacts {
archives javadocJar, sourcesJar
}
def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}
def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}
def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}
def getRepositoryUsername() {
return hasProperty('OSSRH_USERNAME') ? OSSRH_USERNAME : ""
}
def getRepositoryPassword() {
return hasProperty('OSSRH_PASSWORD') ? OSSRH_PASSWORD : ""
}
signing {
required { isReleaseBuild() &&
(gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("publish"))}
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
pom.project {
name POM_NAME
packaging POM_PACKAGING
artifactId POM_ARTIFACT_ID
description POM_DESCRIPTION
url POM_URL
scm {
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
url POM_SCM_URL
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
email POM_DEVELOPER_EMAIL
}
}
}
}
}
}
// TODO: Remove task after upgrading Gradle >= 5.2
import org.gradle.api.artifacts.ResolvedDependency
import org.gradle.api.artifacts.Configuration
import java.io.BufferedWriter
import java.io.FileWriter
tasks.register("generateDependencyReport") {
doLast {
def outputFile = file("${buildDir}/dependency-report.txt")
File parentDir = outputFile.parentFile
if (!parentDir.exists() && !parentDir.mkdirs()) {
throw new IOException("Failed to create directory ${parentDir}")
}
// Create a writer to write the dependency report to the file
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))
try {
writer.write("Manifest: ${project.name}\n")
writer.write("# Generated on ${new Date()}\n\n")
// Iterate through all project configurations
project.configurations.each { Configuration config ->
try {
if (config.isCanBeResolved()) {
writer.write("${config.name}:\n")
def dependencies = config.resolvedConfiguration.firstLevelModuleDependencies
if (dependencies.isEmpty()) {
writer.write(" (No dependencies found)\n")
} else {
dependencies.each { ResolvedDependency dep ->
printDependency(dep, writer, 1)
}
}
} else {
writer.write("${config.name}:\n")
writer.write(" (Cannot be resolved)\n")
}
} catch (Exception e) {
writer.write("${config.name}:\n")
writer.write(" (Resolution failed: ${e.message})\n")
}
writer.write("\n")
}
} finally {
writer.close()
}
println("Dependency report generated: ${outputFile.absolutePath}")
}
}
// Recursive function to print dependencies with proper indentation
void printDependency(ResolvedDependency dependency, BufferedWriter writer, int level) {
def indentation = " " * level
writer.write("${indentation}- ${dependency.moduleGroup}:${dependency.moduleName}:${dependency.moduleVersion}\n")
dependency.children.each { ResolvedDependency child ->
printDependency(child, writer, level + 1)
}
}