Add ability to generate poms for use at build time

Generate poms from Gradle metadata with

    `gradle generatePom`

This will create a root pom with a <modules> section as well as a pom
for every individual module.

These poms are suitable for use with m2eclipse (e.g., File->Import->
Existing Maven project), or at the command line for basic build goals
such as `mvn test`.

These poms are not capable of producing distribution artifacts or
deployment of artifacts.

pom.xml and target will remain in .gitignore as these artifacts are
transient and for developer convenience only.
This commit is contained in:
Chris Beams
2010-11-03 12:59:33 -06:00
parent 2a215e778b
commit 7ea55fdc71
4 changed files with 166 additions and 0 deletions

1
.gitignore vendored
View File

@@ -17,3 +17,4 @@ pom.xml
si.java.hsp
spring-integration-jms/activemq-data/
spring-integration-samples/loanshark/application.log*
target

View File

@@ -263,6 +263,7 @@ project('spring-integration-jms') {
description = 'Spring Integration JMS Support'
dependencies {
compile project(":spring-integration-core")
compile "org.springframework:spring-context:$springVersion"
compile "org.springframework:spring-jms:$springVersion"
compile "org.springframework:spring-tx:$springVersion"
compile ("org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1") { provided = true }
@@ -416,6 +417,8 @@ apply from: "$rootDir/gradle/dist.gradle"
// add tasks like 'snapshotDependencyCheck'
apply from: "${rootDir}/gradle/checks.gradle"
// add 'generatePom' task to generate root pom with <modules> section
apply from: "$rootDir/gradle/maven-root-pom.gradle"
// -----------------------------------------------------------------------------
// Import tasks related to releasing and managing the project

View File

@@ -123,6 +123,7 @@ uploadArchives {
configurePom(deployer.pom)
}
/**
* Install gradle-built artifacts to the local m2 maven cache.
* Further customizes the 'install' task contributed by the 'maven' plugin.
@@ -134,6 +135,105 @@ install {
configurePom(repositories.mavenInstaller.pom)
}
/**
* Generate a Maven pom.xml for use at build time. Dependency information will
* be based on Gradle metadata for the project, and other customizations such
* as licensing information and source compatibility settings are configured
* within.
*
* @author Chris Beams
* @see http://gradle.org/0.9-preview-3/docs/userguide/userguide_single.html#pomBuilder
*/
task generatePom {
group = 'Build'
description = 'Generates a Maven POM file suitable for use in building the project'
generatedPomFileName = "pom.xml"
// enable partial cleaning with `gradle cleanGeneratePom`
outputs.files(generatedPomFileName)
doLast() {
// customize the pom creation process
p = pom {
project {
name = project.description
properties {
setProperty('project.build.sourceEncoding', 'UTF8')
}
build {
plugins {
plugin {
groupId = 'org.apache.maven.plugins'
artifactId = 'maven-compiler-plugin'
configuration {
source = '1.5'
target = '1.5'
}
}
plugin {
groupId = 'org.apache.maven.plugins'
artifactId = 'maven-surefire-plugin'
configuration {
includes {
include = '**/*Tests.java'
}
excludes {
exclude = '**/*Abstract*.java'
}
}
}
}
resources {
resource {
directory = 'src/main/java'
includes = ['**/*']
excludes = ['**/*.java']
}
resource {
directory = 'src/main/resources'
includes = ['**/*']
}
}
testResources {
testResource {
directory = 'src/test/java'
includes = ['**/*']
excludes = ['**/*.java']
}
testResource {
directory = 'src/test/resources'
includes = ['**/*']
}
}
}
}
}
// customizing the artifact id is a special case that must be configured
// after the pom is fully configured, otherwise it'll be overwritten
p.whenConfigured { pom -> pom.artifactId = project.name }
configurePom(p)
// write the pom.xml file out to the filesystem
p.writeTo(generatedPomFileName)
}
// ensure that pom generation happens every time resources are processed
// (which practically means any time a build happens). if the dependencies
// for the project have been updated (in $rootDir/build.gradle), the pom
// will have diffs in it and the developer will be reminded to check in
// the change during the next commit cycle.
//processResources.dependsOn generatePom
}
/**
* Read dynamic 'optional' and 'provided' properties from gradle dependencies
* and translate them to their maven POM equivalents.
*/
def configurePom(def pom) {
pom.whenConfigured { generatedPom ->
def optionalDeps = configurations.testRuntime.allDependencies.findAll { gradleDep ->

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Generate a root Maven pom.xml for use at build time. Contains nothing other
* than a 'modules' section aggregating child projects. This pom will never be
* installed locally or deployed remotely. Child projects will not explicitly
* declare this pom as their parent, given than nothing need be inherited from
* it.
*
* @author Chris Beams
* @see maven-deployment.gradle for per-project generatePom task
*/
task generatePom {
apply plugin: 'maven'
group = 'Build'
description = 'Generates a root Maven pom for convenience.'
generatedPomFileName = "pom.xml"
// enable partial cleaning with `gradle cleanGeneratePom`
outputs.files(generatedPomFileName)
doLast() {
// customize the pom creation process
p = pom {
project {
name = project.description
packaging = 'pom'
modules = javaprojects.collect { project -> project.name }
}
}
// customizing the artifact id is a special case that must be configured
// after the pom is fully configured, otherwise it'll be overwritten
p.whenConfigured { pom -> pom.artifactId = project.name }
// write the pom.xml file out to the filesystem
p.writeTo(generatedPomFileName)
}
// ensure that pom generation happens every time resources are processed
// (which practically means any time a build happens). if the dependencies
// for the project have been updated (in $rootDir/build.gradle), the pom
// will have diffs in it and the developer will be reminded to check in
// the change during the next commit cycle.
//processResources.dependsOn generatePom
}