Skip to content

Commit

Permalink
Improve settings plugin (#2)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aSemy committed Mar 3, 2023
1 parent f8a8b76 commit 3a03ae1
Show file tree
Hide file tree
Showing 22 changed files with 1,053 additions and 101 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ replay_pid*


### IntelliJ ###
.idea
.idea/**
!.idea/codeStyles/
!.idea/codeStyles/**


### Eclipse ###
Expand Down
616 changes: 616 additions & 0 deletions .idea/codeStyles/Project.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 44 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

# Kotlin Binary Compatibility Validator (Mirror Universe)

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

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

buildscript {
dependencies {
// BCV-MU requires the Kotlin Gradle Plugin classes are present
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10")
// BCV-MU requires the Kotlin Gradle Plugin classes are present
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.8.10")
}
}

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

extensions
.getByType<dev.adamko.kotlin.binary_compatibility_validator.BCVSettingsPlugin.Extension>()
.apply {
ignoredProjects.addAll(

// ignore subprojects explicitly
":some-subproject",

// or ignore using a glob pattern
":internal-dependencies:**",
":*-tasks:**",
)
binaryCompatibilityValidator {
ignoredProjects.addAll(

":", // ignore root project
":some-subproject", // ignore subprojects explicitly

// or ignore using a glob pattern
":internal-dependencies:*",
":*-tasks:**",
)

// set the default values for all targets in all enabled-subprojects
defaultTargetValues {
enabled.convention(true)
ignoredClasses.set(listOf("com.package.MyIgnoredClass"))
ignoredMarkers.set(listOf("com.package.MyInternalApiAnnotationMarker"))
ignoredPackages.set(listOf("com.package.my_ignored_package"))
}
}

include(
// these projects will have BCV-MU automatically applied
":common",
":internal-dependencies:alpha:nested",
":internal-dependencies:alpha:nested",
":a-task",

// this subproject is explicitly excluded from BCV
":some-subproject",

// these subprojects will be excluded by glob pattern
":internal-dependencies",
":internal-dependencies:alpha",
":internal-dependencies:beta",
":x-tasks",
":x-tasks:sub1",
":x-tasks:sub1:sub2",
":z-tasks",
":z-tasks:sub1",
":z-tasks:sub1:sub2",
)
```

## License
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ idea {
val readmeCheck by tasks.registering {
group = LifecycleBasePlugin.VERIFICATION_GROUP
val readme = providers.fileContents(layout.projectDirectory.file("README.md")).asText
val minimumGradleTestVersion = libs.versions.testGradleVersion
val supportedGradleVersion = libs.versions.supportedGradleVersion
val kotlinBcvVersion = libs.versions.kotlinx.bcv

doLast {
Expand All @@ -34,7 +34,7 @@ val readmeCheck by tasks.registering {
require("kotlinxBinaryCompatibilityValidatorVersion.set(\"${kotlinBcvVersion.get()}\")" in readme) {
"Incorrect BCV version in README"
}
require("The minimal supported Gradle version is ${minimumGradleTestVersion.get()}" in readme) {
require("The minimal supported Gradle version is ${supportedGradleVersion.get()}" in readme) {
"Incorrect Gradle version in README"
}
}
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:$expectedKotlinDslPluginsVersion")

implementation(libs.gradlePlugin.pluginPublishing)
implementation(libs.gradlePlugin.shadow)
}

java {
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@ kotest = "5.5.5"
kotlinx-bcv = "0.13.0"

gradlePluginPublishPlugin = "1.1.0"
shadowPlugin = "8.1.0"

testGradleVersion = "7.6" # the minimal supported Gradle plugin version, used in functional tests
supportedGradleVersion = "7.6" # the minimal supported Gradle plugin version, used in functional tests

[libraries]

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

## region Test Libraries
kotest-bom = { module = "io.kotest:kotest-bom", version.ref = "kotest" }
kotest-runnerJUnit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotest-assertionsCore = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-property = { module = "io.kotest:kotest-property", version.ref = "kotest" }
kotest-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest" }

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

## region Gradle Plugins
gradlePlugin-pluginPublishing = { module = "com.gradle.publish:plugin-publish-plugin", version.ref = "gradlePluginPublishPlugin" }
gradlePlugin-shadow = { module = "com.github.johnrengelman:shadow", version.ref = "shadowPlugin" }
## endregion
3 changes: 2 additions & 1 deletion modules/bcv-gradle-plugin-functional-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ testing.suites {
inputs.property("projectTestTempDir", projectTestTempDirPath)
systemProperty("projectTestTempDir", projectTestTempDirPath)
systemProperty("integrationTestProjectsDir", "$projectDir/projects")
systemProperty("minimumGradleTestVersion", libs.versions.testGradleVersion.get())
systemProperty("minimumGradleTestVersion", libs.versions.supportedGradleVersion.get())
}
}
}
Expand All @@ -54,6 +54,7 @@ testing.suites {
testTask.configure {
shouldRunAfter(test)
dependsOn(project.configurations.testMavenPublication)
inputs.files(project.configurations.testMavenPublication)

systemProperty("testMavenRepoDir", file(mavenPublishTest.testMavenRepo).canonicalPath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class AndroidLibraryTest : BaseKotlinGradleTest() {
runner {
arguments.add(":kotlin-library:apiCheck")
}
}.build().apply {
}.build {
task(":kotlin-library:apiCheck") shouldHaveOutcome SUCCESS
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ internal class AndroidLibraryTest : BaseKotlinGradleTest() {
runner {
arguments.add(":java-library:apiCheck")
}
}.build().apply {
}.build {
task(":java-library:apiCheck") shouldHaveOutcome SUCCESS
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kotlinx.validation.test

import dev.adamko.kotlin.binary_compatibility_validator.test.utils.*
import dev.adamko.kotlin.binary_compatibility_validator.test.utils.api.*
import io.kotest.assertions.withClue
import io.kotest.matchers.comparables.shouldBeEqualComparingTo
import io.kotest.matchers.string.shouldContain
import java.io.File
Expand Down Expand Up @@ -42,7 +43,6 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
kotlin("Subsub2Class.kt", "jvmMain") {
resolve("/examples/classes/Subsub2Class.kt")
}

}

runner.build {
Expand Down Expand Up @@ -74,13 +74,28 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
kotlin("Subsub2Class.kt", "jvmMain") {
resolve("/examples/classes/Subsub2Class.kt")
}

dir("src/jvmTest/kotlin") {}
kotlin("Subsub2ClassTest.kt", "jvmTest") {
addText(/*language=kotlin*/ """
|package com.company.test
|
|class SubSub2Test {
| fun blah() {
| println("test")
| }
|}
|
""".trimMargin()
)
}
}

runner.buildAndFail {
task(":apiCheck") shouldHaveOutcome FAILED
output shouldContain "API check failed for project :testproject"
shouldNotHaveRunTask(":check")
withClue(output) {
shouldHaveRunTask(":apiCheck", FAILED)
output shouldContain "API check failed for project :testproject"
shouldNotHaveRunTask(":check")
}
}
}

Expand All @@ -101,7 +116,6 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
kotlin("Subsub2Class.kt", "jvmMain") {
resolve("/examples/classes/Subsub2Class.kt")
}

}

runner.build {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kotlinx.validation.test

import dev.adamko.kotlin.binary_compatibility_validator.test.utils.*
import dev.adamko.kotlin.binary_compatibility_validator.test.utils.api.*
import io.kotest.assertions.withClue
import io.kotest.matchers.file.shouldBeAFile
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
Expand Down Expand Up @@ -90,9 +91,11 @@ internal class MultipleJvmTargetsTest : BaseKotlinGradleTest() {
}

runner.buildAndFail {
task(":apiCheck") shouldHaveOutcome FAILED
output shouldContain "API check failed for project :testproject"
shouldNotHaveRunTask(":check")
withClue(output) {
shouldHaveRunTask(":apiCheck") shouldHaveOutcome FAILED
output shouldContain "API check failed for project :testproject"
shouldNotHaveRunTask(":check")
}
}
}

Expand Down

0 comments on commit 3a03ae1

Please sign in to comment.