-
Notifications
You must be signed in to change notification settings - Fork 24
/
build.gradle
361 lines (300 loc) · 11.4 KB
/
build.gradle
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
import org.gradle.api.internal.classpath.ModuleRegistry
import java.util.regex.Pattern
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
mavenCentral()
}
dependencies { classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0" }
}
class VersionString implements Comparable<VersionString> {
static VersionString parse(String value) {
def parts = value.split("-", 2)
def versions = parts[0].split("\\.")
int major = Integer.parseInt(versions[0])
int minor = Integer.parseInt(versions[1])
int patch = versions.length > 2 ? Integer.parseInt(versions[2]) : 0
String channel = null
String channelVersion = null
if (parts.length > 1) {
def pattern = Pattern.compile("([a-zA-Z]+)(\\d+)");
def m = pattern.matcher(parts[1])
if (m.matches()) {
channel = m.group(1)
channelVersion = m.group(2)
}
}
return new VersionString(major, minor, patch, channel, channelVersion)
}
private final int major
private final int minor
private final int patch
private final String channel
private final String channelVersion
VersionString(int major, int minor, int patch, String channel, String channelVersion) {
this.major = major
this.minor = minor
this.patch = patch
this.channel = channel
this.channelVersion = channelVersion
}
@Override
int compareTo(VersionString o) {
return versionInt() <=> o.versionInt()
}
int versionInt() {
def base = 100 * 100 * 100 * major + 100 * 100 * minor + 100 * patch // padding is 1-99
// 3.0.0 vs 3.0.0-alpha10 -> 3.0.0 is greater
switch (channel) {
case "alpha":
base -= 33
case "beta":
base -= 33
case "rc":
base -= 34
base += Integer.parseInt(channelVersion)
break
}
return base
}
@Override
String toString() {
if (channel) {
return "${major}.${minor}.${patch}-${channel}${channelVersion}"
} else {
return "${major}.${minor}.${patch}"
}
}
}
apply plugin: 'groovy'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "com.diffplug.spotless"
group = 'com.deploygate'
version = new File(rootProject.projectDir, 'src/main/resources/VERSION').text.trim()
def archivesBaseName = 'gradle'
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
ext {
releaseVersion = version
// Be careful to set androidGradleVersion's default. Bytecode compatibility needs to drop backward compatibility.
androidGradleVersion = VersionString.parse(System.getenv("TEST_AGP_VERSION") ?: "4.2.0")
gradleVersion = VersionString.parse(gradle.gradleVersion)
requireJava11 = VersionString.parse("7.4.0") <= androidGradleVersion
requireGroovy3 = VersionString.parse("7.0") <= gradleVersion
}
sourceSets {
unrollAcceptanceTest {
groovy.srcDirs += ["src/test/unrollAcceptance"]
resources.srcDirs += test.resources.srcDirs
}
pluginAcceptanceTest {
groovy.srcDirs += ["src/test/acceptance"]
resources.srcDirs += test.resources.srcDirs
}
}
configurations {
unrollAcceptanceTestCompileOnly.extendsFrom testCompileOnly
unrollAcceptanceTestRuntime.extendsFrom testRuntime
unrollAcceptanceTestRuntimeOnly.extendsFrom testRuntimeOnly
unrollAcceptanceTestImplementation.extendsFrom testImplementation
unrollAcceptanceTestApi.extendsFrom testApi
pluginAcceptanceTestCompileOnly.extendsFrom testCompileOnly
pluginAcceptanceTestRuntime.extendsFrom testRuntime
pluginAcceptanceTestRuntimeOnly.extendsFrom testRuntimeOnly
pluginAcceptanceTestImplementation.extendsFrom testImplementation
pluginAcceptanceTestApi.extendsFrom testApi
}
// For testing. The classpaths of this plugin must be specified
task createClasspathManifest {
def outputDir = file("$buildDir/$name")
inputs.files sourceSets.main.runtimeClasspath
outputs.dir outputDir
doLast {
outputDir.mkdirs()
file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join("\n")
}
}
if (requireJava11) {
// since this version, android gradle plugin artifact is targeting Java 11 and we are using it in testing dependencies.
// We need to change target compatibility only for testing.
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_11
} else {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
compileOnly gradleApi()
compileOnly localGroovy()
// Don't enable this on the repository because this artifact may include bytecode incompatibility.
// compileOnly "com.android.tools.build:gradle:$androidGradleVersion"
implementation 'org.jetbrains:annotations:26.0.1'
implementation 'com.google.guava:guava-annotations:r03'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.4.1'
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2' // for jdk 11 or over
testImplementation gradleTestKit()
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.objenesis:objenesis:3.4'
implementation 'net.bytebuddy:byte-buddy:1.15.10'
if (requireGroovy3) {
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
testImplementation 'org.spockframework:spock-junit4:2.3-groovy-3.0'
} else {
testImplementation 'org.spockframework:spock-core:2.3-groovy-2.5'
testImplementation 'org.spockframework:spock-junit4:2.3-groovy-2.5'
}
// for ApplyPluginSpec
testRuntimeOnly "com.android.tools.build:gradle:$androidGradleVersion"
testRuntimeOnly files(createClasspathManifest)
// We can remove this workaround when upgrading Gradle to 7.5
// https://github.com/gradle/gradle/issues/16774#issuecomment-853407822
testRuntimeOnly(files(services.get(ModuleRegistry).getModule("gradle-tooling-api-builders").classpath.asFiles.first()))
}
tasks.create("testUnrollAcceptanceTest", Test) {
testClassesDirs = sourceSets.unrollAcceptanceTest.output.classesDirs
classpath = sourceSets.unrollAcceptanceTest.runtimeClasspath
dependsOn("createClasspathManifest")
}
tasks.create("testPluginAcceptanceTest", Test) {
testClassesDirs = sourceSets.pluginAcceptanceTest.output.classesDirs
classpath = sourceSets.pluginAcceptanceTest.runtimeClasspath
dependsOn("createClasspathManifest")
}
project.tasks.withType(Test).configureEach {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
environment([
"ANDROID_HOME": System.getenv("ANDROID_HOME"),
"TEST_AGP_VERSION": System.getenv("TEST_AGP_VERSION"),
"TEST_GRADLE_VERSION": System.getenv("TEST_GRADLE_VERSION"),
"TEST_SERVER_URL": System.getenv("TEST_SERVER_URL") ?: "http://localhost:3000",
])
}
task javadocJar(type: Jar, dependsOn: groovydoc) {
archiveClassifier.set('javadoc')
from "${buildDir}/javadoc"
}
task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}
def getRepositoryUsername() {
return hasProperty('nexusUsername') ? nexusUsername : ""
}
def getRepositoryPassword() {
return hasProperty('nexusPassword') ? nexusPassword : ""
}
def isRelease() {
return rootProject.ext.releaseVersion =~ /^\d+\.\d+\.\d+$/
}
allprojects {
// spotless requires Java11 so please comment out all spotless configurations if you wanna run on JRE 8
spotless {
ratchetFrom 'origin/master'
encoding 'UTF-8'
java {
importOrder()
removeUnusedImports()
googleJavaFormat('1.16.0').aosp().reflowLongStrings()
formatAnnotations()
indentWithSpaces(4)
}
groovy {
importOrder()
excludeJava()
greclipse('4.26')
indentWithSpaces(4)
}
groovyGradle {
target '*.gradle'
greclipse('4.26')
indentWithSpaces(4)
}
format 'misc', {
target '*.md', '.gitignore', '*.properties'
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
}
// TODO detect violations automatically
// DO: Use org.jetbrains.annotations.{NotNull,Nullable,VisibleForTesting}
// DON'T: Use javax.annotations.{Nonnull,Nullable}, Guavas VisibleForTesting
}
}
afterEvaluate {
publishing {
repositories {
maven {
url = isRelease() ? "https://oss.sonatype.org/service/local/staging/deploy/maven2/" : "https://oss.sonatype.org/content/repositories/snapshots/"
credentials(PasswordCredentials) {
username = getRepositoryUsername()
password = getRepositoryPassword()
}
}
}
publications {
release(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
groupId = project.group
artifactId = archivesBaseName
version = project.version
pom {
name = "Gradle DeployGate Plugin"
description = "This is the DeployGate plugin for the Gradle. You can build and deploy your apps to DeployGate by running a single task."
url = 'https://github.com/DeployGate/gradle-deploygate-plugin'
licenses {
license {
name = "The Apache Software License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution = "repo"
}
}
developers {
developer {
id = "deploygate"
name = "DeployGate"
}
}
scm { url = 'https://github.com/DeployGate/gradle-deploygate-plugin' }
}
}
}
signing {
required { (isRelease() || System.getenv("RELEASE_SCRIPT_TEST") == "true") && gradle.taskGraph.hasTask("publishReleasePublicationToMavenRepository") }
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
publishing.publications.configureEach { publication -> sign publication }
}
}
}
project.afterEvaluate {
def process = "git rev-parse HEAD".execute([], rootDir)
def version_name
if (process.waitFor() == 0) {
version_name = process.text.trim()
} else {
version_name = "unavailable"
}
if (System.getenv("CI") != "true") {
version_name += "(local)"
}
def file = rootProject.file("src/main/resources/VERSION_NAME")
if (file.exists()) {
if (file.text.trim() != version_name) {
file.write(version_name, "UTF-8")
}
} else {
file.write(version_name, "UTF-8")
}
}