1- import com.gradle.publish.*
2- import kotlinx.validation.build.*
3- import org.jetbrains.kotlin.gradle.tasks.*
1+ import kotlinx.validation.build.mavenCentralMetadata
2+ import kotlinx.validation.build.mavenRepositoryPublishing
3+ import kotlinx.validation.build.signPublicationIfKeyPresent
4+ import org.gradle.api.attributes.TestSuiteType.FUNCTIONAL_TEST
5+ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
6+ import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
47
58plugins {
69 kotlin(" jvm" )
710 `java- gradle- plugin`
8- id(" com.gradle.plugin-publish" ) apply false
11+ id(" com.gradle.plugin-publish" )
12+ kotlinx.validation.build.conventions.`java- base`
913 signing
1014 `maven- publish`
15+ `jvm- test- suite`
16+ id(" org.jetbrains.kotlinx.binary-compatibility-validator" )
1117}
1218
13- repositories {
14- mavenCentral()
15- gradlePluginPortal()
16- google()
19+ group = " org.jetbrains.kotlinx"
20+ providers.gradleProperty(" DeployVersion" ).orNull?.let {
21+ version = it
1722}
1823
1924sourceSets {
@@ -22,29 +27,18 @@ sourceSets {
2227 }
2328}
2429
25- sourceSets {
26- create(" functionalTest" ) {
27- withConvention(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet ::class ) {
28- }
29- compileClasspath + = sourceSets.main.get().output + configurations.testRuntimeClasspath
30- runtimeClasspath + = output + compileClasspath
31- }
32- }
33-
34- tasks.register<Test >(" functionalTest" ) {
35- testClassesDirs = sourceSets[" functionalTest" ].output.classesDirs
36- classpath = sourceSets[" functionalTest" ].runtimeClasspath
37- }
38- tasks.check { dependsOn(tasks[" functionalTest" ]) }
39-
4030// While gradle testkit supports injection of the plugin classpath it doesn't allow using dependency notation
4131// to determine the actual runtime classpath for the plugin. It uses isolation, so plugins applied by the build
4232// script are not visible in the plugin classloader. This means optional dependencies (dependent on applied plugins -
4333// for example kotlin multiplatform) are not visible even if they are in regular gradle use. This hack will allow
4434// extending the classpath. It is based upon: https://docs.gradle.org/6.0/userguide/test_kit.html#sub:test-kit-classpath-injection
4535
4636// Create a configuration to register the dependencies against
47- val testPluginRuntimeConfiguration = configurations.register(" testPluginRuntime" )
37+ val testPluginRuntimeConfiguration = configurations.create(" testPluginRuntime" ) {
38+ isCanBeConsumed = false
39+ isCanBeResolved = true
40+ isVisible = false
41+ }
4842
4943// The task that will create a file that stores the classpath needed for the plugin to have additional runtime dependencies
5044// This file is then used in to tell TestKit which classpath to use.
@@ -58,106 +52,144 @@ val createClasspathManifest = tasks.register("createClasspathManifest") {
5852 .withPropertyName(" outputDir" )
5953
6054 doLast {
61- outputDir.mkdirs( )
62- file(outputDir.resolve( " plugin-classpath.txt " )). writeText(testPluginRuntimeConfiguration.get() .joinToString(" \n " ))
55+ file( outputDir.resolve( " plugin-classpath.txt " ) )
56+ . writeText(testPluginRuntimeConfiguration.joinToString(" \n " ))
6357 }
6458}
6559
66- val kotlinVersion: String by project
67- val androidGradlePluginVersion: String = " 7.2.2"
68-
6960dependencies {
7061 implementation(gradleApi())
71- implementation(" org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.2" )
72- implementation(" org.ow2.asm:asm:9.2" )
73- implementation(" org.ow2.asm:asm-tree:9.2" )
74- implementation(" com.googlecode.java-diff-utils:diffutils:1.3.0" )
75- compileOnly(" org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:1.8.10" )
76- // compileOnly("com.android.tools.build:gradle:${androidGradlePluginVersion}")
62+ implementation(libs.kotlinx.metadata)
63+ implementation(libs.ow2.asm)
64+ implementation(libs.ow2.asmTree)
65+ implementation(libs.javaDiffUtils)
66+ compileOnly(libs.gradlePlugin.kotlin)
67+
68+ // Android support is not yet implemented https://github.com/Kotlin/binary-compatibility-validator/issues/94
69+ // compileOnly(libs.gradlePlugin.android)
7770
7871 // The test needs the full kotlin multiplatform plugin loaded as it has no visibility of previously loaded plugins,
7972 // unlike the regular way gradle loads plugins.
80- add(testPluginRuntimeConfiguration.name, " org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:$kotlinVersion " )
81- add(testPluginRuntimeConfiguration.name, " com.android.tools.build:gradle:${androidGradlePluginVersion} " )
82-
83- testImplementation(kotlin(" test-junit" ))
84- " functionalTestImplementation" (files(createClasspathManifest))
85-
86- " functionalTestImplementation" (" org.assertj:assertj-core:3.18.1" )
87- " functionalTestImplementation" (gradleTestKit())
88- " functionalTestImplementation" (kotlin(" test-junit" ))
73+ testPluginRuntimeConfiguration(libs.gradlePlugin.android)
74+ testPluginRuntimeConfiguration(libs.gradlePlugin.kotlin)
8975}
9076
9177tasks.compileKotlin {
92- kotlinOptions.apply {
93- allWarningsAsErrors = true
94-
95- languageVersion = " 1.4"
96- apiVersion = " 1.4"
97- jvmTarget = " 1.8"
98-
78+ compilerOptions {
79+ allWarningsAsErrors.set(true )
80+ @Suppress(" DEPRECATION" ) // Compatibility with Gradle 7 requires Kotlin 1.4
81+ languageVersion.set(KotlinVersion .KOTLIN_1_4 )
82+ apiVersion.set(languageVersion)
83+ jvmTarget.set(JvmTarget .JVM_1_8 )
9984 // Suppressing "w: Language version 1.4 is deprecated and its support will be removed" message
10085 // because LV=1.4 in practice is mandatory as it is a default language version in Gradle 7.0+ for users' kts scripts.
101- freeCompilerArgs + = " -Xsuppress-version-warnings"
86+ freeCompilerArgs.addAll(
87+ " -Xsuppress-version-warnings"
88+ )
10289 }
10390}
10491
10592java {
106- sourceCompatibility = JavaVersion .VERSION_1_8
107- targetCompatibility = JavaVersion .VERSION_1_8
93+ withJavadocJar()
94+ withSourcesJar()
95+ toolchain {
96+ languageVersion.set(JavaLanguageVersion .of(8 ))
97+ }
10898}
10999
110- tasks {
111- compileTestKotlin {
112- kotlinOptions {
113- languageVersion = " 1.9"
114- freeCompilerArgs + = " -Xsuppress-version-warnings"
115- }
116- }
117- test {
118- systemProperty(" overwrite.output" , System .getProperty(" overwrite.output" , " false" ))
119- systemProperty(" testCasesClassesDirs" , sourceSets.test.get().output.classesDirs.asPath)
120- jvmArgs(" -ea" )
100+ tasks.compileTestKotlin {
101+ compilerOptions {
102+ languageVersion.set(KotlinVersion .KOTLIN_1_9 )
121103 }
122104}
123105
124- properties[" DeployVersion" ]?.let { version = it }
106+ tasks.withType<Test >().configureEach {
107+ systemProperty(" overwrite.output" , System .getProperty(" overwrite.output" , " false" ))
108+ systemProperty(" testCasesClassesDirs" , sourceSets.test.get().output.classesDirs.asPath)
109+ jvmArgs(" -ea" )
110+ }
125111
126112publishing {
127113 publications {
128114 create<MavenPublication >(" maven" ) {
129115 from(components[" java" ])
130- mavenCentralMetadata( )
131- mavenCentralArtifacts(project, project.sourceSets.main.get().allSource )
116+ artifact(tasks.javadocJar )
117+ artifact(tasks.sourcesJar )
132118 }
133119
134120 mavenRepositoryPublishing(project)
135121 mavenCentralMetadata()
136122 }
137123
138- publications.withType( MavenPublication :: class ).all {
124+ publications.withType< MavenPublication >( ).all {
139125 signPublicationIfKeyPresent(this )
140126 }
141- }
142127
143- apply (plugin = " org.gradle.java-gradle-plugin" )
144- apply (plugin = " com.gradle.plugin-publish" )
145-
146- extensions.getByType(PluginBundleExtension ::class ).apply {
147- website = " https://github.com/Kotlin/binary-compatibility-validator"
148- vcsUrl = " https://github.com/Kotlin/binary-compatibility-validator"
149- tags = listOf (" kotlin" , " api-management" , " binary-compatibility" )
128+ // a publication will be created automatically by com.gradle.plugin-publish
150129}
151130
131+ @Suppress(" UnstableApiUsage" )
152132gradlePlugin {
153- testSourceSets(sourceSets[" functionalTest" ])
133+ website.set(" https://github.com/Kotlin/binary-compatibility-validator" )
134+ vcsUrl.set(" https://github.com/Kotlin/binary-compatibility-validator" )
135+
136+ plugins.configureEach {
137+ tags.addAll(" kotlin" , " api-management" , " binary-compatibility" )
138+ }
154139
155140 plugins {
156141 create(" binary-compatibility-validator" ) {
157142 id = " org.jetbrains.kotlinx.binary-compatibility-validator"
158143 implementationClass = " kotlinx.validation.BinaryCompatibilityValidatorPlugin"
159144 displayName = " Binary compatibility validator"
160- description = " Produces binary API dumps and compares them in order to verify that binary API is preserved"
145+ description =
146+ " Produces binary API dumps and compares them in order to verify that binary API is preserved"
161147 }
162148 }
163149}
150+
151+ @Suppress(" UnstableApiUsage" )
152+ testing {
153+ suites {
154+ withType<JvmTestSuite >().configureEach {
155+ useJUnit()
156+ dependencies {
157+ implementation(project())
158+ implementation(libs.assertJ.core)
159+ implementation(libs.kotlin.test)
160+ }
161+ }
162+
163+ val test by getting(JvmTestSuite ::class ) {
164+ description = " Regular unit tests"
165+ }
166+
167+ val functionalTest by creating(JvmTestSuite ::class ) {
168+ testType.set(FUNCTIONAL_TEST )
169+ description = " Functional Plugin tests using Gradle TestKit"
170+
171+ dependencies {
172+ implementation(files(createClasspathManifest))
173+
174+ implementation(gradleApi())
175+ implementation(gradleTestKit())
176+ }
177+
178+ targets.configureEach {
179+ testTask.configure {
180+ shouldRunAfter(test)
181+ }
182+ }
183+ }
184+
185+ gradlePlugin.testSourceSets(functionalTest.sources)
186+
187+ tasks.check {
188+ dependsOn(functionalTest)
189+ }
190+ }
191+ }
192+
193+ tasks.withType<Sign >().configureEach {
194+ onlyIf(" only sign if signatory is present" ) { signatory?.keyId != null }
195+ }
0 commit comments