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 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 new file mode 100644 index 00000000..8691d8ef --- /dev/null +++ b/json-schema-validator-bom/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + `java-platform` + convention.publication +} + +configurations.api.configure { + dependencyConstraints.addAllLater( + bomService.coordinates + .map { coordinates -> + coordinates + .distinct() + .map(project.dependencies.constraints::create) + }, + ) +} + +publishing { + publications { + create("jsonSchemaValidatorBom") { + from(components["javaPlatform"]) + } + } +} \ No newline at end of file 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