Skip to content

Commit 65282d1

Browse files
authored
Fixed support for Gradle < 7.0 (#267)
1 parent c00ca4b commit 65282d1

File tree

4 files changed

+124
-18
lines changed

4 files changed

+124
-18
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ The tool allows dumping binary API of a JVM part of a Kotlin library that is pub
2626

2727
## Requirements
2828

29-
Binary compatibility validator plugin requires Gradle `6.0` or newer.
29+
Binary compatibility validator plugin requires Gradle `6.1.1` or newer.
30+
31+
Kotlin version `1.6.20` or newer.
3032

3133
## Setup
3234

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2016-2024 JetBrains s.r.o.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.validation.test
7+
8+
import kotlinx.validation.api.*
9+
import org.assertj.core.api.Assertions
10+
import org.gradle.testkit.runner.GradleRunner
11+
import org.junit.Assume
12+
import org.junit.Test
13+
import kotlin.test.assertTrue
14+
15+
class GradleCompatibilityTest : BaseKotlinGradleTest() {
16+
17+
@Test
18+
fun test8Dot0() {
19+
checkDumpWithGradle("8.0")
20+
}
21+
22+
@Test
23+
fun test7Dot0() {
24+
checkDumpWithGradle("7.0")
25+
}
26+
27+
@Test
28+
fun testMin() {
29+
val runner = test(gradleVersion = "6.1.1", injectPluginClasspath = false) {
30+
buildGradleKts {
31+
resolve("/examples/gradle/base/withPluginMinKotlin.gradle.kts")
32+
}
33+
kotlin("AnotherBuildConfig.kt") {
34+
resolve("/examples/classes/AnotherBuildConfig.kt")
35+
}
36+
37+
runner(withConfigurationCache = false) {
38+
arguments.add(":apiDump")
39+
}
40+
}
41+
42+
skipInDebug(runner)
43+
44+
runner.build().apply {
45+
assertTaskSuccess(":apiDump")
46+
47+
assertTrue(rootProjectApiDump.exists(), "api dump file should exist")
48+
49+
val expected = readFileList("/examples/classes/AnotherBuildConfig.dump")
50+
Assertions.assertThat(rootProjectApiDump.readText()).isEqualToIgnoringNewLines(expected)
51+
}
52+
}
53+
54+
private fun skipInDebug(runner: GradleRunner) {
55+
Assume.assumeFalse(
56+
"The test requires a separate Gradle distributive " +
57+
"so it could not be executed with debug turned on.",
58+
runner.isDebug
59+
)
60+
}
61+
62+
private fun checkDumpWithGradle(gradleVersion: String) {
63+
val runner = test(gradleVersion = gradleVersion, injectPluginClasspath = false) {
64+
buildGradleKts {
65+
resolve("/examples/gradle/base/withPlugin.gradle.kts")
66+
}
67+
kotlin("AnotherBuildConfig.kt") {
68+
resolve("/examples/classes/AnotherBuildConfig.kt")
69+
}
70+
71+
runner {
72+
arguments.add(":apiDump")
73+
}
74+
}
75+
76+
skipInDebug(runner)
77+
78+
runner.build().apply {
79+
assertTaskSuccess(":apiDump")
80+
81+
assertTrue(rootProjectApiDump.exists(), "api dump file should exist")
82+
83+
val expected = readFileList("/examples/classes/AnotherBuildConfig.dump")
84+
Assertions.assertThat(rootProjectApiDump.readText()).isEqualToIgnoringNewLines(expected)
85+
}
86+
}
87+
88+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
plugins {
7+
kotlin("jvm") version "1.6.20"
8+
id("org.jetbrains.kotlinx.binary-compatibility-validator")
9+
}
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
implementation(kotlin("stdlib-jdk8"))
17+
}

src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -650,21 +650,19 @@ private val Project.klibDumpFileName: String
650650
get() = "$name.klib.api"
651651

652652
private fun Project.prepareKlibValidationClasspath(): NamedDomainObjectProvider<Configuration> {
653-
val compilerVersion = project.objects.property(String::class.java).convention("2.0.0")
654-
project.withKotlinPluginVersion { version ->
655-
compilerVersion.set(version)
656-
}
657-
653+
val configName = "bcv-rt-klib-cp"
658654
val dependencyConfiguration =
659-
project.configurations.create("bcv-rt-klib-cp") {
655+
project.configurations.create(configName) {
660656
it.description = "Runtime classpath for running binary-compatibility-validator."
661657
it.isCanBeResolved = false
662658
it.isCanBeConsumed = false
663659
it.isCanBeDeclaredCompat = true
664660
it.isVisible = false
665661
}
666662

667-
project.dependencies.addProvider(dependencyConfiguration.name, compilerVersion.map { version -> "org.jetbrains.kotlin:kotlin-compiler-embeddable:$version" })
663+
project.withKotlinPluginVersion { version ->
664+
project.dependencies.add(configName, "org.jetbrains.kotlin:kotlin-compiler-embeddable:$version")
665+
}
668666

669667
return project.configurations.register("bcv-rt-klib-cp-resolver") {
670668
it.description = "Resolve the runtime classpath for running binary-compatibility-validator."
@@ -677,16 +675,9 @@ private fun Project.prepareKlibValidationClasspath(): NamedDomainObjectProvider<
677675
}
678676

679677
private fun Project.prepareJvmValidationClasspath(): NamedDomainObjectProvider<Configuration> {
680-
val metadataDependencyVersion = project.objects.property(String::class.java).convention("2.0.0")
681-
project.withKotlinPluginVersion { version ->
682-
if (version != null && !version.startsWith("1.")) {
683-
metadataDependencyVersion.set(version)
684-
}
685-
}
686-
687-
678+
val configName = "bcv-rt-jvm-cp"
688679
val dependencyConfiguration =
689-
project.configurations.create("bcv-rt-jvm-cp") {
680+
project.configurations.create(configName) {
690681
it.description = "Runtime classpath for running binary-compatibility-validator."
691682
it.isCanBeResolved = false
692683
it.isCanBeConsumed = false
@@ -696,7 +687,15 @@ private fun Project.prepareJvmValidationClasspath(): NamedDomainObjectProvider<C
696687

697688
project.dependencies.add(dependencyConfiguration.name, "org.ow2.asm:asm:9.6")
698689
project.dependencies.add(dependencyConfiguration.name, "org.ow2.asm:asm-tree:9.6")
699-
project.dependencies.addProvider(dependencyConfiguration.name, metadataDependencyVersion.map { version -> "org.jetbrains.kotlin:kotlin-metadata-jvm:$version" })
690+
project.withKotlinPluginVersion { version ->
691+
val result = when {
692+
version == null -> "2.0.0"
693+
version.startsWith("1.") -> "2.0.0"
694+
else -> version
695+
}
696+
697+
project.dependencies.add(configName, "org.jetbrains.kotlin:kotlin-metadata-jvm:$result")
698+
}
700699

701700
return project.configurations.register("bcv-rt-jvm-cp-resolver") {
702701
it.description = "Resolve the runtime classpath for running binary-compatibility-validator."

0 commit comments

Comments
 (0)