forked from Kotlin/binary-compatibility-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
249 lines (213 loc) · 8.11 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
import kotlinx.kover.gradle.plugin.dsl.MetricType
import kotlinx.validation.build.mavenCentralMetadata
import kotlinx.validation.build.mavenRepositoryPublishing
import kotlinx.validation.build.signPublicationIfKeyPresent
import org.gradle.api.attributes.TestSuiteType.FUNCTIONAL_TEST
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import java.net.URL
plugins {
kotlin("jvm")
`java-gradle-plugin`
id("com.gradle.plugin-publish")
kotlinx.validation.build.conventions.`java-base`
signing
`maven-publish`
`jvm-test-suite`
id("org.jetbrains.kotlinx.binary-compatibility-validator")
alias(libs.plugins.kover)
alias(libs.plugins.dokka)
}
group = "com.mikepenz.kotlinx"
project.findProperty("DeployVersion")?.let {
version = it
}
sourceSets {
test {
java.srcDir("src/test/kotlin")
}
}
// While gradle testkit supports injection of the plugin classpath it doesn't allow using dependency notation
// to determine the actual runtime classpath for the plugin. It uses isolation, so plugins applied by the build
// script are not visible in the plugin classloader. This means optional dependencies (dependent on applied plugins -
// for example kotlin multiplatform) are not visible even if they are in regular gradle use. This hack will allow
// extending the classpath. It is based upon: https://docs.gradle.org/6.0/userguide/test_kit.html#sub:test-kit-classpath-injection
// Create a configuration to register the dependencies against
val testPluginRuntimeConfiguration = configurations.create("testPluginRuntime") {
isCanBeConsumed = false
isCanBeResolved = true
isVisible = false
}
// The task that will create a file that stores the classpath needed for the plugin to have additional runtime dependencies
// This file is then used in to tell TestKit which classpath to use.
val createClasspathManifest = tasks.register("createClasspathManifest") {
val outputDir = buildDir.resolve("cpManifests")
inputs.files(testPluginRuntimeConfiguration)
.withPropertyName("runtimeClasspath")
.withNormalizer(ClasspathNormalizer::class)
outputs.dir(outputDir)
.withPropertyName("outputDir")
doLast {
file(outputDir.resolve("plugin-classpath.txt"))
.writeText(testPluginRuntimeConfiguration.joinToString("\n"))
}
}
dependencies {
implementation(gradleApi())
compileOnly(libs.kotlinx.metadata)
compileOnly(libs.kotlin.compiler.embeddable)
compileOnly(libs.ow2.asm)
compileOnly(libs.ow2.asmTree)
implementation(libs.javaDiffUtils)
compileOnly(libs.gradlePlugin.kotlin)
// Android support is not yet implemented https://github.com/Kotlin/binary-compatibility-validator/issues/94
//compileOnly(libs.gradlePlugin.android)
// The test needs the full kotlin multiplatform plugin loaded as it has no visibility of previously loaded plugins,
// unlike the regular way gradle loads plugins.
testPluginRuntimeConfiguration(libs.gradlePlugin.android)
testPluginRuntimeConfiguration(libs.gradlePlugin.kotlin)
}
tasks.compileKotlin {
compilerOptions {
allWarningsAsErrors.set(true)
@Suppress("DEPRECATION") // Compatibility with Gradle 7 requires Kotlin 1.4
languageVersion.set(KotlinVersion.KOTLIN_1_4)
apiVersion.set(languageVersion)
jvmTarget.set(JvmTarget.JVM_1_8)
// Suppressing "w: Language version 1.4 is deprecated and its support will be removed" message
// because LV=1.4 in practice is mandatory as it is a default language version in Gradle 7.0+ for users' kts scripts.
freeCompilerArgs.addAll(
"-Xexplicit-api=strict",
"-Xsuppress-version-warnings",
"-Xopt-in=kotlin.RequiresOptIn"
)
}
}
java {
withJavadocJar()
withSourcesJar()
}
kotlin {
jvmToolchain(8)
}
tasks.compileTestKotlin {
compilerOptions {
languageVersion.set(KotlinVersion.KOTLIN_1_9)
}
}
tasks.withType<Test>().configureEach {
systemProperty("overwrite.output", System.getProperty("overwrite.output", "false"))
systemProperty("testCasesClassesDirs", sourceSets.test.get().output.classesDirs.asPath)
systemProperty("kover.enabled", project.findProperty("kover.enabled")?.toString().toBoolean())
jvmArgs("-ea")
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
mavenRepositoryPublishing(project)
mavenCentralMetadata()
}
publications.withType<MavenPublication>().all {
signPublicationIfKeyPresent(this)
}
tasks.withType<PublishToMavenRepository>().configureEach {
dependsOn(tasks.withType<Sign>())
}
// a publication will be created automatically by com.gradle.plugin-publish
}
@Suppress("UnstableApiUsage")
gradlePlugin {
website.set("https://github.com/mikepenz/binary-compatibility-validator")
vcsUrl.set("https://github.com/mikepenz/binary-compatibility-validator")
plugins.configureEach {
tags.addAll("kotlin", "api-management", "binary-compatibility")
}
plugins {
create("binary-compatibility-validator") {
id = "com.mikepenz.kotlinx.binary-compatibility-validator"
implementationClass = "kotlinx.validation.BinaryCompatibilityValidatorPlugin"
displayName = "Binary compatibility validator"
description = "Produces binary API dumps and compares them in order to verify that binary API is preserved. Forked plugin with regex filter support."
}
}
}
@Suppress("UnstableApiUsage")
testing {
suites {
withType<JvmTestSuite>().configureEach {
useJUnit()
dependencies {
implementation(project())
implementation(libs.assertJ.core)
implementation(libs.kotlin.test)
}
}
val test by getting(JvmTestSuite::class) {
description = "Regular unit tests"
dependencies {
implementation(libs.kotlinx.metadata)
implementation(libs.kotlin.compiler.embeddable)
implementation(libs.ow2.asm)
implementation(libs.ow2.asmTree)
}
}
val functionalTest by creating(JvmTestSuite::class) {
testType.set(FUNCTIONAL_TEST)
description = "Functional Plugin tests using Gradle TestKit"
dependencies {
implementation(files(createClasspathManifest))
implementation(libs.kotlinx.metadata)
implementation(libs.kotlin.compiler.embeddable)
implementation(gradleApi())
implementation(gradleTestKit())
}
targets.configureEach {
testTask.configure {
shouldRunAfter(test)
}
}
}
gradlePlugin.testSourceSets(functionalTest.sources)
tasks.check {
dependsOn(functionalTest)
}
}
}
tasks.withType<Sign>().configureEach {
onlyIf("only sign if signatory is present") { signatory?.keyId != null }
}
kover {
koverReport {
filters {
excludes {
packages("kotlinx.validation.test")
}
}
verify {
rule {
minBound(80, MetricType.BRANCH)
minBound(90, MetricType.LINE)
}
}
}
// Unfortunately, we can't test both configuration cache use and the test coverage
// simultaneously, so the coverage collection should be enabled explicitly (and that
// will disable configuration cache).
if (!project.findProperty("kover.enabled")?.toString().toBoolean()) {
disable()
}
}
tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
includes.from("Module.md")
sourceLink {
localDirectory.set(rootDir)
remoteUrl.set(URL("https://github.com/Kotlin/binary-compatibility-validator/tree/master"))
remoteLineSuffix.set("#L")
}
samples.from("src/test/kotlin/samples/KlibDumpSamples.kt")
}
}