Skip to content

Commit 3a03ae1

Browse files
authored
Improve settings plugin (#2)
* allow for nested project paths in GradleProjectTest util, and minor doc update * rename testGradleVersion to supportedGradleVersion * make testMavenPublication task dependency more explicit * update from ignoredMarkers to nonPublicMarkers in test case * update from using KGP to KGP-api * allow setting default BCV target values in BCVSettingsPlugin * update test assertions * Add settings plugin test * update README example for settings plugin * try using Shadow plugin... which didn't work, but it might with different config? #1 (comment) * add kotest-datatest in libs.versions.toml * commit code style * update formatting
1 parent f8a8b76 commit 3a03ae1

File tree

22 files changed

+1053
-101
lines changed

22 files changed

+1053
-101
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ replay_pid*
1616

1717

1818
### IntelliJ ###
19-
.idea
19+
.idea/**
20+
!.idea/codeStyles/
21+
!.idea/codeStyles/**
2022

2123

2224
### Eclipse ###

.idea/codeStyles/Project.xml

+616
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+44-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
# Kotlin Binary Compatibility Validator (Mirror Universe)
55

6-
[BCV-MU](https://github.com/adamko-dev/kotlin-binary-compatibility-validator-mu) is a re-imagined [Gradle](https://gradle.org/) Plugin for
6+
[BCV-MU](https://github.com/adamko-dev/kotlin-binary-compatibility-validator-mu) is a
7+
re-imagined [Gradle](https://gradle.org/) Plugin for
78
[Kotlin/binary-compatibility-validator](https://github.com/Kotlin/binary-compatibility-validator).
89

910
This plugin validates the public JVM binary API of libraries to make sure that breaking changes are
@@ -194,28 +195,56 @@ All subprojects are included by default, and can be excluded using BCV-MU config
194195

195196
buildscript {
196197
dependencies {
197-
// BCV-MU requires the Kotlin Gradle Plugin classes are present
198-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10")
198+
// BCV-MU requires the Kotlin Gradle Plugin classes are present
199+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.8.10")
199200
}
200201
}
201202

202203
plugins {
203204
id("dev.adamko.kotlin.binary-compatibility-validator") version "$bcvMuVersion"
204205
}
205206

206-
extensions
207-
.getByType<dev.adamko.kotlin.binary_compatibility_validator.BCVSettingsPlugin.Extension>()
208-
.apply {
209-
ignoredProjects.addAll(
210-
211-
// ignore subprojects explicitly
212-
":some-subproject",
213-
214-
// or ignore using a glob pattern
215-
":internal-dependencies:**",
216-
":*-tasks:**",
217-
)
207+
binaryCompatibilityValidator {
208+
ignoredProjects.addAll(
209+
210+
":", // ignore root project
211+
":some-subproject", // ignore subprojects explicitly
212+
213+
// or ignore using a glob pattern
214+
":internal-dependencies:*",
215+
":*-tasks:**",
216+
)
217+
218+
// set the default values for all targets in all enabled-subprojects
219+
defaultTargetValues {
220+
enabled.convention(true)
221+
ignoredClasses.set(listOf("com.package.MyIgnoredClass"))
222+
ignoredMarkers.set(listOf("com.package.MyInternalApiAnnotationMarker"))
223+
ignoredPackages.set(listOf("com.package.my_ignored_package"))
218224
}
225+
}
226+
227+
include(
228+
// these projects will have BCV-MU automatically applied
229+
":common",
230+
":internal-dependencies:alpha:nested",
231+
":internal-dependencies:alpha:nested",
232+
":a-task",
233+
234+
// this subproject is explicitly excluded from BCV
235+
":some-subproject",
236+
237+
// these subprojects will be excluded by glob pattern
238+
":internal-dependencies",
239+
":internal-dependencies:alpha",
240+
":internal-dependencies:beta",
241+
":x-tasks",
242+
":x-tasks:sub1",
243+
":x-tasks:sub1:sub2",
244+
":z-tasks",
245+
":z-tasks:sub1",
246+
":z-tasks:sub1:sub2",
247+
)
219248
```
220249

221250
## License

build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ idea {
2323
val readmeCheck by tasks.registering {
2424
group = LifecycleBasePlugin.VERIFICATION_GROUP
2525
val readme = providers.fileContents(layout.projectDirectory.file("README.md")).asText
26-
val minimumGradleTestVersion = libs.versions.testGradleVersion
26+
val supportedGradleVersion = libs.versions.supportedGradleVersion
2727
val kotlinBcvVersion = libs.versions.kotlinx.bcv
2828

2929
doLast {
@@ -34,7 +34,7 @@ val readmeCheck by tasks.registering {
3434
require("kotlinxBinaryCompatibilityValidatorVersion.set(\"${kotlinBcvVersion.get()}\")" in readme) {
3535
"Incorrect BCV version in README"
3636
}
37-
require("The minimal supported Gradle version is ${minimumGradleTestVersion.get()}" in readme) {
37+
require("The minimal supported Gradle version is ${supportedGradleVersion.get()}" in readme) {
3838
"Incorrect Gradle version in README"
3939
}
4040
}

buildSrc/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies {
88
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:$expectedKotlinDslPluginsVersion")
99

1010
implementation(libs.gradlePlugin.pluginPublishing)
11+
implementation(libs.gradlePlugin.shadow)
1112
}
1213

1314
java {

gradle/libs.versions.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,29 @@ kotest = "5.5.5"
88
kotlinx-bcv = "0.13.0"
99

1010
gradlePluginPublishPlugin = "1.1.0"
11+
shadowPlugin = "8.1.0"
1112

12-
testGradleVersion = "7.6" # the minimal supported Gradle plugin version, used in functional tests
13+
supportedGradleVersion = "7.6" # the minimal supported Gradle plugin version, used in functional tests
1314

1415
[libraries]
1516

1617
javaDiffUtils = { module = "io.github.java-diff-utils:java-diff-utils", version.ref = "javaDiffUtils" }
1718
kotlinx-bcv = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "kotlinx-bcv" }
1819
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinGradle" }
20+
kotlin-gradlePluginApi = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "kotlinGradle" }
1921

2022
## region Test Libraries
2123
kotest-bom = { module = "io.kotest:kotest-bom", version.ref = "kotest" }
2224
kotest-runnerJUnit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
2325
kotest-assertionsCore = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
2426
kotest-property = { module = "io.kotest:kotest-property", version.ref = "kotest" }
27+
kotest-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest" }
2528

2629
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
2730
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
2831
## endregion
2932

3033
## region Gradle Plugins
3134
gradlePlugin-pluginPublishing = { module = "com.gradle.publish:plugin-publish-plugin", version.ref = "gradlePluginPublishPlugin" }
35+
gradlePlugin-shadow = { module = "com.github.johnrengelman:shadow", version.ref = "shadowPlugin" }
3236
## endregion

modules/bcv-gradle-plugin-functional-tests/build.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ testing.suites {
3333
inputs.property("projectTestTempDir", projectTestTempDirPath)
3434
systemProperty("projectTestTempDir", projectTestTempDirPath)
3535
systemProperty("integrationTestProjectsDir", "$projectDir/projects")
36-
systemProperty("minimumGradleTestVersion", libs.versions.testGradleVersion.get())
36+
systemProperty("minimumGradleTestVersion", libs.versions.supportedGradleVersion.get())
3737
}
3838
}
3939
}
@@ -54,6 +54,7 @@ testing.suites {
5454
testTask.configure {
5555
shouldRunAfter(test)
5656
dependsOn(project.configurations.testMavenPublication)
57+
inputs.files(project.configurations.testMavenPublication)
5758

5859
systemProperty("testMavenRepoDir", file(mavenPublishTest.testMavenRepo).canonicalPath)
5960
}

modules/bcv-gradle-plugin-functional-tests/src/functionalTest/kotlin/kotlinx/validation/test/AndroidLibraryTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal class AndroidLibraryTest : BaseKotlinGradleTest() {
3737
runner {
3838
arguments.add(":kotlin-library:apiCheck")
3939
}
40-
}.build().apply {
40+
}.build {
4141
task(":kotlin-library:apiCheck") shouldHaveOutcome SUCCESS
4242
}
4343
}
@@ -70,7 +70,7 @@ internal class AndroidLibraryTest : BaseKotlinGradleTest() {
7070
runner {
7171
arguments.add(":java-library:apiCheck")
7272
}
73-
}.build().apply {
73+
}.build {
7474
task(":java-library:apiCheck") shouldHaveOutcome SUCCESS
7575
}
7676
}

modules/bcv-gradle-plugin-functional-tests/src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmTargetTest.kt

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kotlinx.validation.test
22

33
import dev.adamko.kotlin.binary_compatibility_validator.test.utils.*
44
import dev.adamko.kotlin.binary_compatibility_validator.test.utils.api.*
5+
import io.kotest.assertions.withClue
56
import io.kotest.matchers.comparables.shouldBeEqualComparingTo
67
import io.kotest.matchers.string.shouldContain
78
import java.io.File
@@ -42,7 +43,6 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
4243
kotlin("Subsub2Class.kt", "jvmMain") {
4344
resolve("/examples/classes/Subsub2Class.kt")
4445
}
45-
4646
}
4747

4848
runner.build {
@@ -74,13 +74,28 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
7474
kotlin("Subsub2Class.kt", "jvmMain") {
7575
resolve("/examples/classes/Subsub2Class.kt")
7676
}
77-
77+
dir("src/jvmTest/kotlin") {}
78+
kotlin("Subsub2ClassTest.kt", "jvmTest") {
79+
addText(/*language=kotlin*/ """
80+
|package com.company.test
81+
|
82+
|class SubSub2Test {
83+
| fun blah() {
84+
| println("test")
85+
| }
86+
|}
87+
|
88+
""".trimMargin()
89+
)
90+
}
7891
}
7992

8093
runner.buildAndFail {
81-
task(":apiCheck") shouldHaveOutcome FAILED
82-
output shouldContain "API check failed for project :testproject"
83-
shouldNotHaveRunTask(":check")
94+
withClue(output) {
95+
shouldHaveRunTask(":apiCheck", FAILED)
96+
output shouldContain "API check failed for project :testproject"
97+
shouldNotHaveRunTask(":check")
98+
}
8499
}
85100
}
86101

@@ -101,7 +116,6 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
101116
kotlin("Subsub2Class.kt", "jvmMain") {
102117
resolve("/examples/classes/Subsub2Class.kt")
103118
}
104-
105119
}
106120

107121
runner.build {

modules/bcv-gradle-plugin-functional-tests/src/functionalTest/kotlin/kotlinx/validation/test/MultipleJvmTargetsTest.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kotlinx.validation.test
22

33
import dev.adamko.kotlin.binary_compatibility_validator.test.utils.*
44
import dev.adamko.kotlin.binary_compatibility_validator.test.utils.api.*
5+
import io.kotest.assertions.withClue
56
import io.kotest.matchers.file.shouldBeAFile
67
import io.kotest.matchers.shouldBe
78
import io.kotest.matchers.string.shouldContain
@@ -90,9 +91,11 @@ internal class MultipleJvmTargetsTest : BaseKotlinGradleTest() {
9091
}
9192

9293
runner.buildAndFail {
93-
task(":apiCheck") shouldHaveOutcome FAILED
94-
output shouldContain "API check failed for project :testproject"
95-
shouldNotHaveRunTask(":check")
94+
withClue(output) {
95+
shouldHaveRunTask(":apiCheck") shouldHaveOutcome FAILED
96+
output shouldContain "API check failed for project :testproject"
97+
shouldNotHaveRunTask(":check")
98+
}
9699
}
97100
}
98101

0 commit comments

Comments
 (0)