-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
237 lines (207 loc) · 7.79 KB
/
build.gradle.kts
File metadata and controls
237 lines (207 loc) · 7.79 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
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
@file:Suppress("UnstableApiUsage")
import org.gradle.api.plugins.JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME
import org.gradle.api.plugins.JavaPlugin.JAVADOC_ELEMENTS_CONFIGURATION_NAME
import org.gradle.api.plugins.JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME
import org.gradle.api.plugins.JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME
import org.gradle.plugin.compatibility.compatibility
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.android.lint)
alias(libs.plugins.jetbrains.dokka)
alias(libs.plugins.mavenPublish)
alias(libs.plugins.pluginPublish)
alias(libs.plugins.spotless)
}
version = providers.gradleProperty("VERSION_NAME").get()
group = providers.gradleProperty("GROUP").get()
description = providers.gradleProperty("POM_DESCRIPTION").get()
dokka { dokkaPublications.html { outputDirectory = rootDir.resolve("docs/api") } }
kotlin {
explicitApi()
@OptIn(ExperimentalAbiValidation::class) abiValidation { enabled = true }
val jdkRelease = "17"
compilerOptions {
allWarningsAsErrors = true
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
apiVersion = KotlinVersion.KOTLIN_2_2
languageVersion = apiVersion
jvmTarget = JvmTarget.fromTarget(jdkRelease)
jvmDefault = JvmDefaultMode.NO_COMPATIBILITY
freeCompilerArgs.add("-Xjdk-release=$jdkRelease")
}
target.compilations.configureEach {
compileJavaTaskProvider { options.release = jdkRelease.toInt() }
}
}
lint {
baseline = file("gradle/lint-baseline.xml")
ignoreTestFixturesSources = true
ignoreTestSources = true
warningsAsErrors = true
disable += "NewerVersionAvailable"
disable += "GradleDependency"
disable += "AndroidGradlePluginVersion"
}
spotless {
kotlin { ktfmt(libs.ktfmt.get().version).googleStyle() }
kotlinGradle { ktfmt(libs.ktfmt.get().version).googleStyle() }
}
val testPluginClasspath by configurations.registering {
isCanBeResolved = true
description = "Plugins used in integration tests could be resolved in classpath."
}
val testKit by sourceSets.creating
val testKitImplementation by configurations.getting
configurations.configureEach {
when (name) {
API_ELEMENTS_CONFIGURATION_NAME,
RUNTIME_ELEMENTS_CONFIGURATION_NAME,
JAVADOC_ELEMENTS_CONFIGURATION_NAME,
SOURCES_ELEMENTS_CONFIGURATION_NAME ->
outgoing {
// Main/current capability.
capability("com.gradleup.shadow:shadow-gradle-plugin:$version")
// Historical capabilities.
capability("io.github.goooler.shadow:shadow-gradle-plugin:$version")
capability("com.github.johnrengelman:shadow:$version")
capability("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:$version")
capability("gradle.plugin.com.github.johnrengelman:shadow:$version")
capability("com.github.jengelman.gradle.plugins:shadow:$version")
}
}
}
publishing.publications.withType<MavenPublication>().configureEach {
// We don't care about capabilities being unmappable to Maven.
suppressPomMetadataWarningsFor(API_ELEMENTS_CONFIGURATION_NAME)
suppressPomMetadataWarningsFor(RUNTIME_ELEMENTS_CONFIGURATION_NAME)
suppressPomMetadataWarningsFor(JAVADOC_ELEMENTS_CONFIGURATION_NAME)
suppressPomMetadataWarningsFor(SOURCES_ELEMENTS_CONFIGURATION_NAME)
}
configurations.named(API_ELEMENTS_CONFIGURATION_NAME) {
attributes.attribute(
// TODO: https://github.com/gradle/gradle/issues/24608
GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE,
objects.named(libs.versions.minGradle.get()),
)
}
val testGradleVersion: String =
providers.gradleProperty("testGradleVersion").orNull.let {
val value = if (it == null || it == "current") GradleVersion.current().version else it
logger.lifecycle("Using Gradle $value in tests")
value
}
dependencies {
compileOnly(libs.develocity)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.kotlin.reflect)
api(libs.apache.ant) // Types from Ant are exposed in the public API.
implementation(libs.apache.commonsCodec)
implementation(libs.apache.commonsIo)
implementation(libs.apache.log4j)
implementation(libs.jdependency)
implementation(libs.jdom2)
implementation(libs.kotlin.metadata)
implementation(libs.plexus.utils)
implementation(libs.plexus.xml)
testKitImplementation(gradleTestKit())
testKitImplementation(libs.assertk)
testPluginClasspath(libs.foojayResolver)
testPluginClasspath(libs.develocity)
testPluginClasspath(libs.kotlin.gradlePlugin)
testPluginClasspath(libs.pluginPublish)
lintChecks(libs.androidx.gradlePluginLints)
}
testing.suites {
getByName<JvmTestSuite>("test") { dependencies { implementation(libs.xmlunit) } }
register<JvmTestSuite>("documentTest") {
targets.configureEach {
testTask {
val docsDir =
file("docs").also {
if (!it.exists() || !it.isDirectory)
error("Docs dir $it does not exist or is not a directory.")
}
// Add docs as an input directory to trigger ManualCodeSnippetTests re-run on changes.
inputs.dir(docsDir)
systemProperty("DOCS_DIR", docsDir.absolutePath)
}
}
}
register<JvmTestSuite>("functionalTest") {
targets.configureEach {
testTask {
// Required to enable `IssueExtension` for all tests.
systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
// Required to test configuration cache in tests when using withDebug().
// See https://github.com/gradle/gradle/issues/22765#issuecomment-1339427241.
jvmArgs(
"--add-opens=java.base/java.util=ALL-UNNAMED",
"--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED",
"--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens=java.base/java.net=ALL-UNNAMED",
)
}
}
dependencies {
implementation(libs.apache.maven.model)
implementation(libs.moshi)
implementation(libs.moshi.kotlin)
}
}
withType<JvmTestSuite>().configureEach {
useJUnitJupiter(libs.junit.bom.map { checkNotNull(it.version) })
dependencies {
implementation(testKit.output)
implementation(libs.assertk)
}
targets.configureEach {
testTask {
systemProperty("TEST_GRADLE_VERSION", testGradleVersion)
develocity {
testRetry {
maxRetries = 2
maxFailures = 10
}
}
}
}
}
}
gradlePlugin {
website = providers.gradleProperty("POM_URL")
vcsUrl = providers.gradleProperty("POM_URL")
plugins {
create("com.gradleup.shadow") {
implementationClass = "com.github.jengelman.gradle.plugins.shadow.ShadowPlugin"
displayName = providers.gradleProperty("POM_NAME").get()
description = providers.gradleProperty("POM_DESCRIPTION").get()
tags = listOf("onejar", "shade", "fatjar", "uberjar")
compatibility { features { configurationCache = true } }
}
}
testSourceSets(sourceSets["test"], sourceSets["functionalTest"], sourceSets["documentTest"])
}
// This part should be placed after testing.suites to ensure the test sourceSets are created.
kotlin.target.compilations {
val main by getting
getByName("functionalTest") {
// Import main and its classpath as dependencies and establish internal visibility.
associateWith(main)
}
}
tasks.pluginUnderTestMetadata { pluginClasspath.from(testPluginClasspath) }
tasks.check { dependsOn(tasks.withType<Test>()) }
tasks.clean {
delete +=
listOf(
projectDir.resolve(".gradle"),
projectDir.resolve(".kotlin"),
dokka.dokkaPublications.html.map { it.outputDirectory },
// Generated by MkDocs.
rootDir.resolve("site"),
)
}