-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathbuild.gradle.kts
273 lines (235 loc) · 8.95 KB
/
build.gradle.kts
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
import com.gradle.develocity.agent.gradle.test.PredictiveTestSelectionProfile.FAST
import com.gradle.develocity.agent.gradle.test.PredictiveTestSelectionProfile.STANDARD
import groovy.json.JsonSlurper
import groovy.json.JsonParserType
// Upgrade transitive dependencies in plugin classpath
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
constraints {
// Dependency of 'com.github.breadmoirai.github-release:2.5.2'
classpath("com.squareup.okio:okio:3.10.2") // CVE-2023-3635
}
}
}
plugins {
id("groovy")
id("java-gradle-plugin")
id("maven-publish")
id("signing")
id("codenarc")
id("com.gradle.plugin-publish") version "1.3.0"
id("com.github.breadmoirai.github-release") version "2.5.2"
id("org.gradle.wrapper-upgrade") version "0.12"
}
val releaseVersion = releaseVersion()
val releaseNotes = releaseNotes()
val isCI = providers.environmentVariable("CI").isPresent
group = "org.gradle.android"
version = releaseVersion.get()
description = "A Gradle plugin to fix Android caching problems"
repositories {
google()
mavenCentral()
}
dependencies {
val versions = mapOf(
"agp" to "8.1.4",
"sdkBuildTools" to "31.1.1",
"spock" to "2.3-groovy-3.0",
)
compileOnly(gradleApi())
compileOnly("com.android.tools.build:gradle:${versions["agp"]}")
compileOnly("com.android.tools:common:${versions["sdkBuildTools"]}")
compileOnly("com.android.tools:sdk-common:${versions["sdkBuildTools"]}")
implementation("com.google.guava:guava:33.4.0-jre")
testImplementation(gradleTestKit())
testImplementation("com.android.tools.build:gradle:${versions["agp"]}")
testImplementation(platform("org.spockframework:spock-bom:${versions["spock"]}"))
testImplementation("org.spockframework:spock-core") { exclude(group = "org.codehaus.groovy") }
testImplementation("org.spockframework:spock-junit4") { exclude(group = "org.codehaus.groovy") }
testImplementation("org.junit.jupiter:junit-jupiter-api")
}
wrapperUpgrade {
gradle {
create("android-cache-fix-gradle-plugin") {
repo = "gradle/android-cache-fix-gradle-plugin"
}
}
}
java {
toolchain {
// AGP 7+ only supports JDK 11+
languageVersion = JavaLanguageVersion.of(11)
}
}
// Main plugin publishing metadata
gradlePlugin {
website = "https://github.com/gradle/android-cache-fix-gradle-plugin"
vcsUrl = "https://github.com/gradle/android-cache-fix-gradle-plugin"
plugins {
create("androidCacheFixPlugin") {
id = "org.gradle.android.cache-fix"
displayName = "Gradle Android cache fix plugin"
description = releaseNotes.get()
implementationClass = "org.gradle.android.AndroidCacheFixPlugin"
tags.addAll("android", "cache", "fix")
}
}
}
// A local repo we publish our library to for testing in order to workaround limitations
// in the TestKit plugin classpath.
val localRepo = layout.buildDirectory.dir("local-repo")
val isProdPortal = providers.systemProperty("gradle.portal.url").orNull == null
// The legacy groupId gradle.plugin.* is only allowed when the plugin
// has already been published
val pluginGroupId: String = if (isCI && isProdPortal) "gradle.plugin.org.gradle.android" else project.group.toString()
publishing {
publications {
create<MavenPublication>("pluginMaven") {
groupId = pluginGroupId
pom {
name.set("Android Cache Fix Gradle Plugin")
description.set("A Gradle plugin to workaround cache issues in Android builds")
url.set("https://github.com/gradle/android-cache-fix-gradle-plugin")
licenses {
license {
name.set("Apache-2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
name.set("The Gradle team")
organization.set("Gradle Inc.")
organizationUrl.set("https://gradle.com")
}
}
scm {
developerConnection.set("scm:git:https://github.com/gradle/android-cache-fix-gradle-plugin.git")
url.set("https://github.com/gradle/android-cache-fix-gradle-plugin")
}
}
}
}
repositories {
maven {
url = localRepo.get().asFile.toURI()
}
}
}
tasks.withType<Jar>().configureEach {
into(".") {
from(layout.projectDirectory.file("LICENSE"))
from(layout.projectDirectory.dir("release/distribution"))
}
}
// Configuration common to all test tasks
tasks.withType<Test>().configureEach {
dependsOn(tasks.publish)
workingDir = projectDir
systemProperty("local.repo", projectDir.toPath().relativize(localRepo.get().asFile.toPath()).toString())
systemProperty("pluginGroupId", pluginGroupId)
systemProperty("org.gradle.android.cache-fix.version", version)
useJUnitPlatform()
develocity.testRetry {
maxRetries = if (isCI) 1 else 0
maxFailures = 20
}
}
tasks.test {
develocity.predictiveTestSelection {
profile = STANDARD
}
}
val latestVersion = providers.gradleProperty("org.gradle.android.latestKnownAgpVersion")
val supportedVersions = readSupportedVersions()
check(latestVersion.get() in supportedVersions) {
"The project must be updated to support AGP $latestVersion. Please add it to supported versions."
}
supportedVersions.keys.forEach { androidVersion ->
val versionSpecificTest = tasks.register<Test>(androidTestTaskName(androidVersion)) {
description = "Runs the multi-version tests for AGP $androidVersion"
group = "verification"
systemProperty("org.gradle.android.testVersion", androidVersion)
project.providers.environmentVariable("ZULU_JDK").orNull?.let {
systemProperty("org.gradle.android.java_zulu_path", it)
}
project.providers.environmentVariable("ZULU_ALT_JDK").orNull?.let {
systemProperty("org.gradle.android.java_zulu_alt_path", it)
}
if (androidVersion >= "8.0.0") {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
develocity.predictiveTestSelection {
profile = FAST
}
}
tasks.check {
dependsOn(versionSpecificTest)
}
}
fun androidTestTaskName(androidVersion: String): String {
return "testAndroid${normalizeVersion(androidVersion)}"
}
fun normalizeVersion(version: String): String {
return version.replace("[.\\-]".toRegex(), "_")
}
// A basic sanity check to run before running all test tasks
tasks.register("sanityCheck") {
dependsOn(tasks.withType<CodeNarc>(), tasks.validatePlugins)
}
tasks.withType<ValidatePlugins>().configureEach {
failOnWarning = true
enableStricterValidation = true
}
signing {
// Require publications to be signed when :publishPlugins task is included in the TaskGraph
setRequired({ gradle.taskGraph.hasTask(":publishPlugins") })
useInMemoryPgpKeys(
providers.environmentVariable("PGP_SIGNING_KEY").orNull,
providers.environmentVariable("PGP_SIGNING_KEY_PASSPHRASE").orNull
)
}
githubRelease {
token(providers.environmentVariable("ANDROID_CACHE_FIX_PLUGIN_GIT_TOKEN").orNull)
owner = "gradle"
repo = "android-cache-fix-gradle-plugin"
releaseName = releaseVersion
tagName = releaseVersion.map { "v$it" }
prerelease = false
overwrite = false
generateReleaseNotes = false
body = releaseNotes
targetCommitish = "main"
}
val createReleaseTag = tasks.register<CreateGitTag>("createReleaseTag") {
// Ensure tag is created only after successful publishing
mustRunAfter(tasks.publishPlugins)
tagName = githubRelease.tagName.map { it.toString() }
}
tasks.githubRelease {
dependsOn(createReleaseTag)
}
tasks.withType<com.gradle.publish.PublishTask>().configureEach {
notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/21283")
}
fun releaseVersion(): Provider<String> {
val releaseVersionFile = layout.projectDirectory.file("release/version.txt")
return providers.fileContents(releaseVersionFile).asText.map { it.trim() }
}
fun releaseNotes(): Provider<String> {
val releaseNotesFile = layout.projectDirectory.file("release/changes.md")
return providers.fileContents(releaseNotesFile).asText.map { it.trim() }
}
@Suppress("UNCHECKED_CAST")
fun readSupportedVersions(): Map<String, Array<String>> {
val versionFile = providers.fileContents(layout.projectDirectory.file("src/main/resources/versions.json5"))
val slurper = JsonSlurper().setType(JsonParserType.LAX)
val json = slurper.parse(versionFile.asBytes.get()) as Map<String, Map<String, Array<String>>>
return json.getValue("supportedVersions")
}