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
4
7
5
8
plugins {
6
9
kotlin(" jvm" )
7
10
`java- gradle- plugin`
8
- id(" com.gradle.plugin-publish" ) apply false
11
+ id(" com.gradle.plugin-publish" )
12
+ kotlinx.validation.build.conventions.`java- base`
9
13
signing
10
14
`maven- publish`
15
+ `jvm- test- suite`
16
+ id(" org.jetbrains.kotlinx.binary-compatibility-validator" )
11
17
}
12
18
13
- repositories {
14
- mavenCentral()
15
- gradlePluginPortal()
16
- google()
19
+ group = " org.jetbrains.kotlinx"
20
+ providers.gradleProperty(" DeployVersion" ).orNull?.let {
21
+ version = it
17
22
}
18
23
19
24
sourceSets {
@@ -22,29 +27,18 @@ sourceSets {
22
27
}
23
28
}
24
29
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
-
40
30
// While gradle testkit supports injection of the plugin classpath it doesn't allow using dependency notation
41
31
// to determine the actual runtime classpath for the plugin. It uses isolation, so plugins applied by the build
42
32
// script are not visible in the plugin classloader. This means optional dependencies (dependent on applied plugins -
43
33
// for example kotlin multiplatform) are not visible even if they are in regular gradle use. This hack will allow
44
34
// extending the classpath. It is based upon: https://docs.gradle.org/6.0/userguide/test_kit.html#sub:test-kit-classpath-injection
45
35
46
36
// 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
+ }
48
42
49
43
// The task that will create a file that stores the classpath needed for the plugin to have additional runtime dependencies
50
44
// This file is then used in to tell TestKit which classpath to use.
@@ -58,106 +52,144 @@ val createClasspathManifest = tasks.register("createClasspathManifest") {
58
52
.withPropertyName(" outputDir" )
59
53
60
54
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 " ))
63
57
}
64
58
}
65
59
66
- val kotlinVersion: String by project
67
- val androidGradlePluginVersion: String = " 7.2.2"
68
-
69
60
dependencies {
70
61
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)
77
70
78
71
// The test needs the full kotlin multiplatform plugin loaded as it has no visibility of previously loaded plugins,
79
72
// 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)
89
75
}
90
76
91
77
tasks.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 )
99
84
// Suppressing "w: Language version 1.4 is deprecated and its support will be removed" message
100
85
// 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
+ )
102
89
}
103
90
}
104
91
105
92
java {
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
+ }
108
98
}
109
99
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 )
121
103
}
122
104
}
123
105
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
+ }
125
111
126
112
publishing {
127
113
publications {
128
114
create<MavenPublication >(" maven" ) {
129
115
from(components[" java" ])
130
- mavenCentralMetadata( )
131
- mavenCentralArtifacts(project, project.sourceSets.main.get().allSource )
116
+ artifact(tasks.javadocJar )
117
+ artifact(tasks.sourcesJar )
132
118
}
133
119
134
120
mavenRepositoryPublishing(project)
135
121
mavenCentralMetadata()
136
122
}
137
123
138
- publications.withType( MavenPublication :: class ).all {
124
+ publications.withType< MavenPublication >( ).all {
139
125
signPublicationIfKeyPresent(this )
140
126
}
141
- }
142
127
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
150
129
}
151
130
131
+ @Suppress(" UnstableApiUsage" )
152
132
gradlePlugin {
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
+ }
154
139
155
140
plugins {
156
141
create(" binary-compatibility-validator" ) {
157
142
id = " org.jetbrains.kotlinx.binary-compatibility-validator"
158
143
implementationClass = " kotlinx.validation.BinaryCompatibilityValidatorPlugin"
159
144
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"
161
147
}
162
148
}
163
149
}
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