Skip to content

Commit

Permalink
Fixed support for Gradle < 7.0 (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanshin authored Aug 2, 2024
1 parent c00ca4b commit 65282d1
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ The tool allows dumping binary API of a JVM part of a Kotlin library that is pub

## Requirements

Binary compatibility validator plugin requires Gradle `6.0` or newer.
Binary compatibility validator plugin requires Gradle `6.1.1` or newer.

Kotlin version `1.6.20` or newer.

## Setup

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2016-2024 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

package kotlinx.validation.test

import kotlinx.validation.api.*
import org.assertj.core.api.Assertions
import org.gradle.testkit.runner.GradleRunner
import org.junit.Assume
import org.junit.Test
import kotlin.test.assertTrue

class GradleCompatibilityTest : BaseKotlinGradleTest() {

@Test
fun test8Dot0() {
checkDumpWithGradle("8.0")
}

@Test
fun test7Dot0() {
checkDumpWithGradle("7.0")
}

@Test
fun testMin() {
val runner = test(gradleVersion = "6.1.1", injectPluginClasspath = false) {
buildGradleKts {
resolve("/examples/gradle/base/withPluginMinKotlin.gradle.kts")
}
kotlin("AnotherBuildConfig.kt") {
resolve("/examples/classes/AnotherBuildConfig.kt")
}

runner(withConfigurationCache = false) {
arguments.add(":apiDump")
}
}

skipInDebug(runner)

runner.build().apply {
assertTaskSuccess(":apiDump")

assertTrue(rootProjectApiDump.exists(), "api dump file should exist")

val expected = readFileList("/examples/classes/AnotherBuildConfig.dump")
Assertions.assertThat(rootProjectApiDump.readText()).isEqualToIgnoringNewLines(expected)
}
}

private fun skipInDebug(runner: GradleRunner) {
Assume.assumeFalse(
"The test requires a separate Gradle distributive " +
"so it could not be executed with debug turned on.",
runner.isDebug
)
}

private fun checkDumpWithGradle(gradleVersion: String) {
val runner = test(gradleVersion = gradleVersion, injectPluginClasspath = false) {
buildGradleKts {
resolve("/examples/gradle/base/withPlugin.gradle.kts")
}
kotlin("AnotherBuildConfig.kt") {
resolve("/examples/classes/AnotherBuildConfig.kt")
}

runner {
arguments.add(":apiDump")
}
}

skipInDebug(runner)

runner.build().apply {
assertTaskSuccess(":apiDump")

assertTrue(rootProjectApiDump.exists(), "api dump file should exist")

val expected = readFileList("/examples/classes/AnotherBuildConfig.dump")
Assertions.assertThat(rootProjectApiDump.readText()).isEqualToIgnoringNewLines(expected)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2016-2020 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

plugins {
kotlin("jvm") version "1.6.20"
id("org.jetbrains.kotlinx.binary-compatibility-validator")
}

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
}
33 changes: 16 additions & 17 deletions src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -650,21 +650,19 @@ private val Project.klibDumpFileName: String
get() = "$name.klib.api"

private fun Project.prepareKlibValidationClasspath(): NamedDomainObjectProvider<Configuration> {
val compilerVersion = project.objects.property(String::class.java).convention("2.0.0")
project.withKotlinPluginVersion { version ->
compilerVersion.set(version)
}

val configName = "bcv-rt-klib-cp"
val dependencyConfiguration =
project.configurations.create("bcv-rt-klib-cp") {
project.configurations.create(configName) {
it.description = "Runtime classpath for running binary-compatibility-validator."
it.isCanBeResolved = false
it.isCanBeConsumed = false
it.isCanBeDeclaredCompat = true
it.isVisible = false
}

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

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

private fun Project.prepareJvmValidationClasspath(): NamedDomainObjectProvider<Configuration> {
val metadataDependencyVersion = project.objects.property(String::class.java).convention("2.0.0")
project.withKotlinPluginVersion { version ->
if (version != null && !version.startsWith("1.")) {
metadataDependencyVersion.set(version)
}
}


val configName = "bcv-rt-jvm-cp"
val dependencyConfiguration =
project.configurations.create("bcv-rt-jvm-cp") {
project.configurations.create(configName) {
it.description = "Runtime classpath for running binary-compatibility-validator."
it.isCanBeResolved = false
it.isCanBeConsumed = false
Expand All @@ -696,7 +687,15 @@ private fun Project.prepareJvmValidationClasspath(): NamedDomainObjectProvider<C

project.dependencies.add(dependencyConfiguration.name, "org.ow2.asm:asm:9.6")
project.dependencies.add(dependencyConfiguration.name, "org.ow2.asm:asm-tree:9.6")
project.dependencies.addProvider(dependencyConfiguration.name, metadataDependencyVersion.map { version -> "org.jetbrains.kotlin:kotlin-metadata-jvm:$version" })
project.withKotlinPluginVersion { version ->
val result = when {
version == null -> "2.0.0"
version.startsWith("1.") -> "2.0.0"
else -> version
}

project.dependencies.add(configName, "org.jetbrains.kotlin:kotlin-metadata-jvm:$result")
}

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

0 comments on commit 65282d1

Please sign in to comment.