From d8ab525eb0dc66a2eee21cf573340c1d4f445be5 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Sun, 2 Mar 2025 10:59:59 +0100 Subject: [PATCH 1/4] Add dependnecy constrains for bom artifact --- json-schema-validator-bom/build.gradle.kts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 json-schema-validator-bom/build.gradle.kts diff --git a/json-schema-validator-bom/build.gradle.kts b/json-schema-validator-bom/build.gradle.kts new file mode 100644 index 00000000..b7cba318 --- /dev/null +++ b/json-schema-validator-bom/build.gradle.kts @@ -0,0 +1,27 @@ +plugins { + `java-platform` + convention.publication +} + +private val bomProjectName = name + +configurations.api.configure { + dependencyConstraints.addAllLater( + provider { + rootProject.allprojects.filter { + it.pluginManager.hasPlugin("maven-publish") && + it.name != bomProjectName + }.map { + project.dependencies.constraints.create("${it.group}:${it.name}:${it.version}") + } + }, + ) +} + +publishing { + publications { + create("jsonSchemaValidatorBom") { + from(components["javaPlatform"]) + } + } +} \ No newline at end of file From cc3b67322d75971cd826f42c9b130b9a1cda4f70 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Sun, 2 Mar 2025 10:43:08 +0100 Subject: [PATCH 2/4] Exclude bom project from api validation --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5060e5f4..3db07d4c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ allprojects { } apiValidation { - ignoredProjects += listOf("benchmark", "test-suites") + ignoredProjects += listOf("benchmark", "test-suites", "json-schema-validator-bom") } val ossrhUsername: String by project.ext From dec81da65e4c749eecfbee6167d16b5236316b1d Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Sun, 2 Mar 2025 18:18:04 +0100 Subject: [PATCH 3/4] Add bom to settings --- settings.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 65290fcb..ac804c24 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,4 +5,5 @@ rootProject.name = "json-schema-validator-root" include(":test-suites") include(":benchmark") include(":json-schema-validator") -include(":json-schema-validator-objects") \ No newline at end of file +include(":json-schema-validator-objects") +include(":json-schema-validator-bom") \ No newline at end of file From fdd103e094729f312bf0d62e2b5f8f9e2122bf24 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Sun, 2 Mar 2025 18:37:13 +0100 Subject: [PATCH 4/4] Add Bom service to collect coordinates --- .../kotlin/convention.publication.gradle.kts | 28 +++++++++++++++++++ json-schema-validator-bom/build.gradle.kts | 16 ++++------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/buildSrc/src/main/kotlin/convention.publication.gradle.kts b/buildSrc/src/main/kotlin/convention.publication.gradle.kts index e9305080..e701900f 100644 --- a/buildSrc/src/main/kotlin/convention.publication.gradle.kts +++ b/buildSrc/src/main/kotlin/convention.publication.gradle.kts @@ -9,6 +9,34 @@ val javadocJar by tasks.registering(Jar::class) { fun getExtraString(name: String) = ext[name]?.toString() +/** + * Create a service for collecting the coordinates of all artifacts that should be included in the bom. + */ +abstract class BomService : BuildService { + /** Coordinates that will be included in the BOM. */ + abstract val coordinates: SetProperty +} + +val bomService: BomService = + gradle.sharedServices.registerIfAbsent("bomService", BomService::class).get() + +extensions.add("bomService", bomService) + +/** Controls whether the current subproject will be included in the kotest-bom. */ +val includeInBom: Property = + objects.property().convention(project.name != "json-schema-validator-bom") + +extensions.add>("includeInBom", includeInBom) + +bomService.coordinates + .addAll( + provider { + project.run { "$group:$name:$version" } + }.zip(includeInBom) { coordinates, include -> + if (include) listOf(coordinates) else emptyList() + }, + ) + afterEvaluate { publishing { diff --git a/json-schema-validator-bom/build.gradle.kts b/json-schema-validator-bom/build.gradle.kts index b7cba318..8691d8ef 100644 --- a/json-schema-validator-bom/build.gradle.kts +++ b/json-schema-validator-bom/build.gradle.kts @@ -3,18 +3,14 @@ plugins { convention.publication } -private val bomProjectName = name - configurations.api.configure { dependencyConstraints.addAllLater( - provider { - rootProject.allprojects.filter { - it.pluginManager.hasPlugin("maven-publish") && - it.name != bomProjectName - }.map { - project.dependencies.constraints.create("${it.group}:${it.name}:${it.version}") - } - }, + bomService.coordinates + .map { coordinates -> + coordinates + .distinct() + .map(project.dependencies.constraints::create) + }, ) }