From 647267b764311c6968afb051dc21e966f25dd1a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Mon, 13 Jan 2025 16:34:23 +0100 Subject: [PATCH] Publish module-alignment metadata (#2075) --- build.gradle | 15 +++++++++------ gradle/publishMaven.gradle | 4 +++- spock-bom/bom.gradle | 35 +++++++++++++---------------------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index 7c6d3a0799..9d7da19a41 100644 --- a/build.gradle +++ b/build.gradle @@ -101,6 +101,8 @@ apply from: script("ide") boolean isCiServer = System.env["CI"] || System.env["GITHUB_ACTIONS"] subprojects { + if (it.name == "spock-bom") return + apply plugin: "java-library" apply plugin: "groovy" apply plugin: "jacoco" @@ -160,6 +162,7 @@ subprojects { } dependencies { + api platform(projects.spockBom) implementation(project.name == "spock-gradle" ? [] : groovylibs.groovy) } @@ -238,7 +241,7 @@ tasks.register("collectTestXml") { tasks.register("codeCoverageReport", JacocoReport) { group = 'Coverage reports' description = "Creates an aggregate coverage for the whole project." - def reportingProjects = subprojects + def reportingProjects = subprojects - project(projects.spockBom.path) dependsOn(reportingProjects.tasks.collectMany { it.withType(Test) }) additionalSourceDirs.from(reportingProjects.sourceSets.main.allSource.srcDirs) @@ -348,8 +351,8 @@ tasks.register("tagRelease", Exec) { tasks.register("javadoc", Javadoc) { title "Spock Framework API Documentation ($variantLessVersion)" destinationDir file("build/javadoc/$variantLessVersion") - source subprojects.collect { project -> project.tasks.named("javadoc").map { it.source } } - classpath = files(subprojects.collect { project -> project.tasks.named("javadoc").map { it.classpath } }) + source((subprojects - project(projects.spockBom.path)).collect { project -> project.tasks.named("javadoc").map { it.source } }) + classpath = files((subprojects - project(projects.spockBom.path)).collect { project -> project.tasks.named("javadoc").map { it.classpath } }) } configureJavadoc(tasks.named("javadoc"), true) @@ -358,9 +361,9 @@ tasks.register("groovydoc", Groovydoc) { docTitle "Spock Framework API Documentation ($variantLessVersion)" windowTitle "Spock Framework API Documentation ($variantLessVersion)" destinationDir file("build/groovydoc/$variantLessVersion") - source subprojects.collect { project -> project.tasks.named("groovydoc").map { it.source } } - classpath = files(subprojects.collect { project -> project.tasks.named("groovydoc").map { it.classpath } }) - groovyClasspath = files(projects.spockCore.dependencyProject.tasks.named("groovydoc").map { it.groovyClasspath }) + source((subprojects - project(projects.spockBom.path)).collect { project -> project.tasks.named("groovydoc").map { it.source } }) + classpath = files((subprojects - project(projects.spockBom.path)).collect { project -> project.tasks.named("groovydoc").map { it.classpath } }) + groovyClasspath = files(project(projects.spockCore.path).tasks.named("groovydoc").map { it.groovyClasspath }) access = GroovydocAccess.PROTECTED processScripts = false diff --git a/gradle/publishMaven.gradle b/gradle/publishMaven.gradle index 1bebb1289f..52ae5b8508 100644 --- a/gradle/publishMaven.gradle +++ b/gradle/publishMaven.gradle @@ -10,7 +10,9 @@ publishing { maven(MavenPublication) { afterEvaluate { pom.packaging = project.ext.packaging - if (project.ext.packaging != "pom") { + if (project.ext.packaging == "pom") { + from(components.javaPlatform) + } else { from(components.java) artifact(sourcesJar) artifact(javadocJar) diff --git a/spock-bom/bom.gradle b/spock-bom/bom.gradle index 063fb4926b..7c4b0d89d6 100644 --- a/spock-bom/bom.gradle +++ b/spock-bom/bom.gradle @@ -1,21 +1,18 @@ -apply from: script("publishMaven") - -def modifyBom = { xml -> - def projectNode = xml.asNode() - - projectNode.appendNode('properties').appendNode('spock.version', project.fullVersion) - - def dependencyManagement = projectNode.appendNode('dependencyManagement').appendNode('dependencies') +plugins { + id('java-platform') +} +apply from: script('publishMaven') - def mvnProjects = project.parent.subprojects.findAll { it.plugins.hasPlugin('maven-publish') } // find all published projects - mvnProjects -= project // don't self reference +(rootProject.subprojects - project).each { + evaluationDependsOn(it.path) +} - String groupId = project.group - mvnProjects.name.each { - dependencyManagement.appendNode('dependency').with { dep -> - dep.appendNode('groupId', groupId) - dep.appendNode('artifactId', it) - dep.appendNode('version', '${spock.version}') +dependencies { + constraints { + def mvnProjects = rootProject.subprojects.findAll { it.plugins.hasPlugin('maven-publish') } // find all published projects + mvnProjects -= project // don't self reference + mvnProjects.each { + api("${it.group}:${it.name}:${it.version}") } } } @@ -23,9 +20,3 @@ def modifyBom = { xml -> ext.displayName = 'Spock Framework - Bill of Materials' description = 'This bill of materials provides managed spock dependencies.' ext.packaging = 'pom' - -publishing.publications.maven { - pom { - withXml modifyBom - } -}