Skip to content

Commit b5640f7

Browse files
committed
use git-tag based versioning, use dev-publish-plugin (replacing maven-publish-test.gradle.kts), tidy up functional tests, exclusive-filter DevMavenRepo, tidy up & update buildscript config
1 parent 550cd4c commit b5640f7

File tree

21 files changed

+291
-215
lines changed

21 files changed

+291
-215
lines changed

build.gradle.kts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
import buildsrc.utils.excludeGeneratedGradleDsl
1+
import buildsrc.utils.generatedKotlinDslAccessorDirs
22

33
plugins {
44
buildsrc.conventions.base
55
idea
66
}
77

88
group = "dev.adamko.kotlin.binary_compatibility_validator"
9-
version = "0.2.0-SNAPSHOT"
9+
project.version = object {
10+
private val gitVersion = project.gitVersion
11+
override fun toString(): String = gitVersion.get()
12+
}
1013

1114
idea {
1215
module {
13-
excludeGeneratedGradleDsl(layout)
14-
excludeDirs = excludeDirs + layout.files(
15-
".idea",
16-
"gradle/wrapper",
17-
)
16+
excludeDirs = excludeDirs +
17+
layout.generatedKotlinDslAccessorDirs() +
18+
layout.files(
19+
".idea",
20+
"gradle/wrapper",
21+
)
1822
}
1923
}
2024

@@ -42,3 +46,14 @@ val readmeCheck by tasks.registering {
4246
tasks.check {
4347
dependsOn(readmeCheck)
4448
}
49+
50+
val projectVersion by tasks.registering {
51+
description = "prints the project version"
52+
group = "help"
53+
val version = providers.provider { project.version }
54+
inputs.property("version", version)
55+
outputs.cacheIf("logging task, it should always run") { false }
56+
doLast {
57+
logger.quiet("${version.orNull}")
58+
}
59+
}

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies {
1010
implementation(libs.gradlePlugin.bcvMu)
1111
implementation(libs.gradlePlugin.pluginPublishing)
1212
implementation(libs.gradlePlugin.shadow)
13+
implementation(libs.gradlePlugin.devPublish)
1314
}
1415

1516
java {

buildSrc/src/main/kotlin/buildsrc/conventions/maven-publish-test.gradle.kts

Lines changed: 0 additions & 104 deletions
This file was deleted.

buildSrc/src/main/kotlin/buildsrc/utils/gradle.kt

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,97 @@
11
package buildsrc.utils
22

3+
import java.io.File
34
import org.gradle.api.Project
45
import org.gradle.api.artifacts.Configuration
56
import org.gradle.api.component.AdhocComponentWithVariants
7+
import org.gradle.api.file.ProjectLayout
68
import org.gradle.api.file.RelativePath
79
import org.gradle.api.tasks.SourceSet
8-
import org.gradle.kotlin.dsl.get
10+
import org.gradle.kotlin.dsl.*
11+
import org.gradle.util.GradleVersion
12+
13+
14+
/** The current Gradle version */
15+
internal val CurrentGradleVersion: GradleVersion
16+
get() = GradleVersion.current()
17+
18+
19+
/** @see GradleVersion.compareTo */
20+
internal operator fun GradleVersion.compareTo(version: String): Int =
21+
compareTo(GradleVersion.version(version))
22+
23+
24+
/**
25+
* Mark this [Configuration] as one that should be used to declare dependencies in
26+
* [Project.dependencies] block.
27+
*
28+
* Declarable Configurations should be extended by [resolvable] and [consumable] Configurations.
29+
*
30+
* ```
31+
* isCanBeResolved = false
32+
* isCanBeConsumed = false
33+
* isCanBeDeclared = true
34+
* ```
35+
*/
36+
internal fun Configuration.declarable(
37+
visible: Boolean = false,
38+
) {
39+
isCanBeResolved = false
40+
isCanBeConsumed = false
41+
canBeDeclared(true)
42+
isVisible = visible
43+
}
44+
945

1046
/**
1147
* Mark this [Configuration] as one that will be consumed by other subprojects.
1248
*
1349
* ```
1450
* isCanBeResolved = false
1551
* isCanBeConsumed = true
52+
* isCanBeDeclared = false
1653
* ```
1754
*/
18-
fun Configuration.asProvider() {
55+
internal fun Configuration.consumable(
56+
visible: Boolean = true,
57+
) {
1958
isCanBeResolved = false
2059
isCanBeConsumed = true
60+
canBeDeclared(false)
61+
isVisible = visible
2162
}
2263

64+
2365
/**
2466
* Mark this [Configuration] as one that will consume artifacts from other subprojects (also known as 'resolving')
2567
*
2668
* ```
2769
* isCanBeResolved = true
2870
* isCanBeConsumed = false
71+
* isCanBeDeclared = false
2972
* ```
30-
* */
31-
fun Configuration.asConsumer() {
73+
*/
74+
internal fun Configuration.resolvable(
75+
visible: Boolean = false,
76+
) {
3277
isCanBeResolved = true
3378
isCanBeConsumed = false
79+
canBeDeclared(false)
80+
isVisible = visible
81+
}
82+
83+
84+
/**
85+
* Enable/disable [Configuration.isCanBeDeclared] only if it is supported by the
86+
* [CurrentGradleVersion]
87+
*
88+
* This function should be removed when the minimal supported Gradle version is 8.2.
89+
*/
90+
@Suppress("UnstableApiUsage")
91+
private fun Configuration.canBeDeclared(value: Boolean) {
92+
if (CurrentGradleVersion >= "8.2") {
93+
isCanBeDeclared = value
94+
}
3495
}
3596

3697

@@ -81,3 +142,19 @@ fun SourceSet.configurationNames() =
81142
javadocElementsConfigurationName,
82143
sourcesElementsConfigurationName,
83144
)
145+
146+
/** exclude generated Gradle code, so it doesn't clog up search results */
147+
fun ProjectLayout.generatedKotlinDslAccessorDirs(): Set<File> {
148+
149+
val generatedSrcDirs = listOf(
150+
"kotlin-dsl-accessors",
151+
"kotlin-dsl-external-plugin-spec-builders",
152+
"kotlin-dsl-plugins",
153+
)
154+
155+
return projectDirectory.asFile.walk()
156+
.filter { it.isDirectory && it.parentFile.name in generatedSrcDirs }
157+
.flatMap { file ->
158+
file.walk().maxDepth(1).filter { it.isDirectory }.toList()
159+
}.toSet()
160+
}
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
11
package buildsrc.utils
22

3+
import java.io.File
34
import org.gradle.api.file.ProjectLayout
4-
import org.gradle.plugins.ide.idea.model.IdeaModule
5-
6-
7-
/** exclude generated Gradle code, so it doesn't clog up search results */
8-
fun IdeaModule.excludeGeneratedGradleDsl(layout: ProjectLayout) {
9-
10-
val generatedSrcDirs = listOf(
11-
"kotlin-dsl-accessors",
12-
"kotlin-dsl-external-plugin-spec-builders",
13-
"kotlin-dsl-plugins",
14-
)
15-
16-
excludeDirs.addAll(
17-
layout.projectDirectory.asFile.walk()
18-
.filter { it.isDirectory && it.parentFile.name in generatedSrcDirs }
19-
.flatMap { file ->
20-
file.walk().maxDepth(1).filter { it.isDirectory }.toList()
21-
}
22-
)
23-
}

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ kotlinx-bcv = "0.13.2"
99

1010
gradlePluginPublishPlugin = "1.2.0"
1111
shadowPlugin = "8.1.0"
12+
devPublish = "0.2.0"
1213
bcvMu = "0.0.3"
14+
#bcvMu = "0.2.0-SNAPSHOT"
1315

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

@@ -35,4 +37,5 @@ junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "jun
3537
gradlePlugin-bcvMu = { module = "dev.adamko.kotlin.binary_compatibility_validator:bcv-gradle-plugin", version.ref = "bcvMu" }
3638
gradlePlugin-pluginPublishing = { module = "com.gradle.publish:plugin-publish-plugin", version.ref = "gradlePluginPublishPlugin" }
3739
gradlePlugin-shadow = { module = "com.github.johnrengelman:shadow", version.ref = "shadowPlugin" }
40+
gradlePlugin-devPublish = { module = "dev.adamko.gradle:dev-publish-plugin", version.ref = "devPublish" }
3841
## endregion

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
plugins {
22
buildsrc.conventions.`kotlin-gradle-plugin-tests`
3-
buildsrc.conventions.`maven-publish-test`
3+
id("dev.adamko.dev-publish")
44
`java-test-fixtures`
55
`jvm-test-suite`
66
}
77

88
description = "Functional tests for bcv-gradle-plugin"
99

1010
dependencies {
11-
testMavenPublication(projects.modules.bcvGradlePlugin)
11+
devPublication(projects.modules.bcvGradlePlugin)
1212

1313
testFixturesApi(gradleTestKit())
1414

@@ -52,10 +52,11 @@ testing.suites {
5252
targets.configureEach {
5353
testTask.configure {
5454
shouldRunAfter(test)
55-
dependsOn(project.configurations.testMavenPublication)
56-
inputs.files(project.configurations.testMavenPublication)
57-
58-
systemProperty("testMavenRepoDir", file(mavenPublishTest.testMavenRepo).canonicalPath)
55+
dependsOn(tasks.updateDevRepo)
56+
systemProperty(
57+
"devMavenRepoDir",
58+
devPublish.devMavenRepo.asFile.get().invariantSeparatorsPath,
59+
)
5960
}
6061
}
6162
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private fun FunSpec.createTestFixturesProject(
125125
buildGradleKts = """
126126
|plugins {
127127
| kotlin("jvm") version "1.7.10"
128-
| id("dev.adamko.kotlin.binary-compatibility-validator") version "0.2.0-SNAPSHOT"
128+
| id("dev.adamko.kotlin.binary-compatibility-validator") version "+"
129129
| `java-test-fixtures`
130130
|}
131131
|

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,8 @@ buildscript {
152152
}
153153
}
154154
155-
156155
plugins {
157-
id("dev.adamko.kotlin.binary-compatibility-validator") version "0.2.0-SNAPSHOT"
156+
id("dev.adamko.kotlin.binary-compatibility-validator") version "+"
158157
}
159158
160159
include(

modules/bcv-gradle-plugin-functional-tests/src/functionalTest/resources/examples/gradle/base/androidJavaLibrary.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("com.android.library")
3-
id("dev.adamko.kotlin.binary-compatibility-validator") version "0.2.0-SNAPSHOT"
3+
id("dev.adamko.kotlin.binary-compatibility-validator") version "+"
44
}
55

66
android {

0 commit comments

Comments
 (0)