Skip to content

Commit fdd103e

Browse files
committed
Add Bom service to collect coordinates
1 parent dec81da commit fdd103e

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

buildSrc/src/main/kotlin/convention.publication.gradle.kts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ val javadocJar by tasks.registering(Jar::class) {
99

1010
fun getExtraString(name: String) = ext[name]?.toString()
1111

12+
/**
13+
* Create a service for collecting the coordinates of all artifacts that should be included in the bom.
14+
*/
15+
abstract class BomService : BuildService<BuildServiceParameters.None> {
16+
/** Coordinates that will be included in the BOM. */
17+
abstract val coordinates: SetProperty<String>
18+
}
19+
20+
val bomService: BomService =
21+
gradle.sharedServices.registerIfAbsent("bomService", BomService::class).get()
22+
23+
extensions.add("bomService", bomService)
24+
25+
/** Controls whether the current subproject will be included in the kotest-bom. */
26+
val includeInBom: Property<Boolean> =
27+
objects.property<Boolean>().convention(project.name != "json-schema-validator-bom")
28+
29+
extensions.add<Property<Boolean>>("includeInBom", includeInBom)
30+
31+
bomService.coordinates
32+
.addAll(
33+
provider {
34+
project.run { "$group:$name:$version" }
35+
}.zip(includeInBom) { coordinates, include ->
36+
if (include) listOf(coordinates) else emptyList()
37+
},
38+
)
39+
1240
afterEvaluate {
1341
publishing {
1442

json-schema-validator-bom/build.gradle.kts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@ plugins {
33
convention.publication
44
}
55

6-
private val bomProjectName = name
7-
86
configurations.api.configure {
97
dependencyConstraints.addAllLater(
10-
provider {
11-
rootProject.allprojects.filter {
12-
it.pluginManager.hasPlugin("maven-publish") &&
13-
it.name != bomProjectName
14-
}.map {
15-
project.dependencies.constraints.create("${it.group}:${it.name}:${it.version}")
16-
}
17-
},
8+
bomService.coordinates
9+
.map { coordinates ->
10+
coordinates
11+
.distinct()
12+
.map(project.dependencies.constraints::create)
13+
},
1814
)
1915
}
2016

0 commit comments

Comments
 (0)