From 4672c2a1f7aec677b12478665ef3f01ad9d72269 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Mon, 9 Dec 2013 15:51:49 -0600 Subject: [PATCH] SEC-2430: Add Maven BOM --- bom/build.gradle | 8 +++ build.gradle | 2 +- .../src/main/groovy/MavenBomPlugin.groovy | 19 +++++++ buildSrc/src/main/groovy/MavenBomTask.groovy | 55 +++++++++++++++++++ .../gradle-plugins/maven-bom.properties | 1 + gradle/javaprojects.gradle | 4 ++ gradle/maven-deployment.gradle | 1 - settings.gradle | 3 + 8 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 bom/build.gradle create mode 100644 buildSrc/src/main/groovy/MavenBomPlugin.groovy create mode 100644 buildSrc/src/main/groovy/MavenBomTask.groovy create mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/maven-bom.properties diff --git a/bom/build.gradle b/bom/build.gradle new file mode 100644 index 0000000000..a1d5e6ca75 --- /dev/null +++ b/bom/build.gradle @@ -0,0 +1,8 @@ +apply plugin: 'maven-bom' +apply from: "$rootDir/gradle/maven-deployment.gradle" + +generatePom.enabled = false + +mavenBom { + projects = coreModuleProjects +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7ec219a10d..86519149d1 100644 --- a/build.gradle +++ b/build.gradle @@ -54,7 +54,7 @@ sonarRunner { } // Set up different subproject lists for individual configuration -ext.javaProjects = subprojects.findAll { project -> project.name != 'docs' && project.name != 'manual' && project.name != 'guides' } +ext.javaProjects = subprojects.findAll { project -> project.name != 'docs' && project.name != 'manual' && project.name != 'guides' && project.name != 'spring-security-bom' } ext.sampleProjects = subprojects.findAll { project -> project.name.startsWith('spring-security-samples') } ext.itestProjects = subprojects.findAll { project -> project.name.startsWith('itest') } ext.coreModuleProjects = javaProjects - sampleProjects - itestProjects diff --git a/buildSrc/src/main/groovy/MavenBomPlugin.groovy b/buildSrc/src/main/groovy/MavenBomPlugin.groovy new file mode 100644 index 0000000000..2f8c076786 --- /dev/null +++ b/buildSrc/src/main/groovy/MavenBomPlugin.groovy @@ -0,0 +1,19 @@ +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.plugins.* +import org.gradle.api.tasks.* +import org.gradle.api.tasks.TaskAction + +public class MavenBomPlugin implements Plugin { + static String MAVEN_BOM_TASK_NAME = "mavenBom" + + public void apply(Project project) { + project.plugins.apply(JavaPlugin) + project.plugins.apply(MavenPlugin) + project.task(MAVEN_BOM_TASK_NAME, type: MavenBomTask, group: 'Generate', description: 'Configures the pom as a Maven Build of Materials (BOM)') + project.install.dependsOn project.mavenBom + } +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/MavenBomTask.groovy b/buildSrc/src/main/groovy/MavenBomTask.groovy new file mode 100644 index 0000000000..a18312f6c9 --- /dev/null +++ b/buildSrc/src/main/groovy/MavenBomTask.groovy @@ -0,0 +1,55 @@ +import groovy.xml.MarkupBuilder + +import org.gradle.api.DefaultTask +import org.gradle.api.Project +import org.gradle.api.tasks.* + +public class MavenBomTask extends DefaultTask { + + Set projects + + File bomFile + + + public MavenBomTask() { + this.group = "Generate" + this.description = "Generates a Maven Build of Materials (BOM). See http://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") + } + + @TaskAction + public void configureBom() { + project.configurations.archives.artifacts.clear() + + bomFile.parentFile.mkdirs() + bomFile.write("Maven Build of Materials (BOM). See http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies") + project.artifacts { + // work around GRADLE-2406 by attaching text artifact + archives(bomFile) + } + project.install { + repositories.mavenInstaller { + pom.whenConfigured { + 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) + } + } + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/maven-bom.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/maven-bom.properties new file mode 100644 index 0000000000..7ca5209b37 --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/maven-bom.properties @@ -0,0 +1 @@ +implementation-class=MavenBomPlugin diff --git a/gradle/javaprojects.gradle b/gradle/javaprojects.gradle index 4496b3d0d7..a5ec8d0c03 100644 --- a/gradle/javaprojects.gradle +++ b/gradle/javaprojects.gradle @@ -203,3 +203,7 @@ task javadocJar(type: Jar) { classifier = 'javadoc' from javadoc } + +artifacts { + archives javadocJar +} diff --git a/gradle/maven-deployment.gradle b/gradle/maven-deployment.gradle index c9bca8f605..9bde55263e 100644 --- a/gradle/maven-deployment.gradle +++ b/gradle/maven-deployment.gradle @@ -9,7 +9,6 @@ task sourceJar(type: Jar) { artifacts { archives sourceJar - archives javadocJar } // Configuration for SpringSource s3 maven deployer diff --git a/settings.gradle b/settings.gradle index 78019307f7..e4ba8a0b67 100644 --- a/settings.gradle +++ b/settings.gradle @@ -88,3 +88,6 @@ rootProject.children.each {project -> //assert project.projectDir.isDirectory() //assert project.buildFile.isFile() } + +include 'bom' +findProject(':bom').name = 'spring-security-bom'