diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy index 936f8e2a..188833eb 100644 --- a/buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy +++ b/buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy @@ -46,6 +46,7 @@ class ArtifactoryPlugin implements Plugin { } defaults { publications('mavenJava') + publishConfigs('archives') } } } diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/MavenBomPlugin.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/MavenBomPlugin.groovy index 71ed5787..f3d995e0 100644 --- a/buildSrc/src/main/groovy/io/spring/gradle/convention/MavenBomPlugin.groovy +++ b/buildSrc/src/main/groovy/io/spring/gradle/convention/MavenBomPlugin.groovy @@ -17,8 +17,6 @@ package io.spring.gradle.convention import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.plugins.JavaPlatformPlugin -import org.springframework.gradle.CopyPropertiesPlugin import org.springframework.gradle.maven.SpringMavenPlugin /** @@ -27,9 +25,44 @@ import org.springframework.gradle.maven.SpringMavenPlugin */ class MavenBomPlugin implements Plugin { + static String MAVEN_BOM_TASK_NAME = "mavenBom" + + @Override void apply(Project project) { - project.plugins.apply(JavaPlatformPlugin) + + // Declares a new configuration that will be used to associate with Project artifacts + // (namely, the Maven BOM file). + project.configurations { + archives + } + + project.group = project.rootProject.group project.plugins.apply(SpringMavenPlugin) - project.plugins.apply(CopyPropertiesPlugin) + + Utils.skipProjectWithSonarQubePlugin(project) + + project.task(MAVEN_BOM_TASK_NAME, type: MavenBomTask, group: 'Generate', + description: 'Configures the Maven POM as a Maven BOM (Bill of Materials)') + + project.tasks.artifactoryPublish.dependsOn project.mavenBom + project.tasks.publishToOssrh.dependsOn project.mavenBom + + project.rootProject.allprojects.each { p -> + p.plugins.withType(SpringMavenPlugin) { + if (!project.name.equals(p.name)) { + project.mavenBom.projects.add(p) + } + } + } + + // TODO: Shouldn't this be { archives project.mavenBom } according to: + // https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#getArtifacts-- + // TODO: Is this even necessary since this block is defined in MavenBomTask? + project.artifacts { + archives project.mavenBom.bomFile + } + + // TODO: Why? + Utils.configureDeployArtifactsTask(project) } } diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/MavenBomTask.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/MavenBomTask.groovy new file mode 100644 index 00000000..bed6233c --- /dev/null +++ b/buildSrc/src/main/groovy/io/spring/gradle/convention/MavenBomTask.groovy @@ -0,0 +1,73 @@ +package io.spring.gradle.convention + +import org.gradle.api.DefaultTask +import org.gradle.api.Project +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +class MavenBomTask extends DefaultTask { + + @OutputFile + File bomFile + + @Internal + Set projects = [] + + @Input + Set getProjectNames() { + return projects*.name as Set + } + + MavenBomTask() { + + this.group = "Generate" + this.description = "Generates a Maven BOM (Bill of Materials)." + + " See https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies" + this.projects = project.subprojects + this.bomFile = project.file("${->project.buildDir}/maven-bom/${->project.name}-${->project.version}.txt") + this.outputs.upToDateWhen { false } + } + + @TaskAction + void configureBom() { + + bomFile.parentFile.mkdirs() + bomFile.write("Maven BOM (Bill of Materials)" + + " See https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies") + + // TODO: Shouldn't this be { archives project.mavenBom } according to: + // https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#getArtifacts-- + project.artifacts { + // Workaround GRADLE-2406 by attaching text artifact + archives(bomFile) + } + + project.publishing { + publications { + mavenJava(MavenPublication) { + pom { + packaging = "pom" + withXml { + asNode().children().last() + { + delegate.dependencyManagement { + delegate.dependencies { + projects.sort { dep -> "$dep.group:$dep.name" }.each { p -> + delegate.dependency { + delegate.groupId(p.group) + delegate.artifactId(p.name) + delegate.version(p.version) + } + } + } + } + } + } + } + } + } + } + } +} diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/gemfire-server.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/gemfire-server.properties deleted file mode 100644 index bb6a3057..00000000 --- a/buildSrc/src/main/resources/META-INF/gradle-plugins/gemfire-server.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=build.GemFireServerPlugin \ No newline at end of file diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/io.spring.convention.bom.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/io.spring.convention.maven-bom.properties similarity index 100% rename from buildSrc/src/main/resources/META-INF/gradle-plugins/io.spring.convention.bom.properties rename to buildSrc/src/main/resources/META-INF/gradle-plugins/io.spring.convention.maven-bom.properties diff --git a/spring-geode-bom/spring-geode-bom.gradle b/spring-geode-bom/spring-geode-bom.gradle index 54253b26..5963d586 100644 --- a/spring-geode-bom/spring-geode-bom.gradle +++ b/spring-geode-bom/spring-geode-bom.gradle @@ -1,13 +1 @@ -import io.spring.gradle.convention.SpringModulePlugin - -apply plugin: 'io.spring.convention.bom' - -sonarqube.skipProject = true - -project.rootProject.allprojects.each { p -> - p.plugins.withType(SpringModulePlugin) { - if (!project.name.equals(p.name)) { - project.mavenBom.projects.add(p) - } - } -} +apply plugin: 'io.spring.convention.maven-bom'