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.
272 lines
10 KiB
Groovy
272 lines
10 KiB
Groovy
/*
|
|
* 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.
|
|
*/
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Tasks related to deploying Maven artifacts.
|
|
//
|
|
// @author Chris Beams
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// check that upload-related properties are defined and fail early if not
|
|
// these properties ('s3AccessKey', etc) should be defined in
|
|
// 'gradle.properties' in $HOME/.gradle/gradle.properties
|
|
def requiredProps = version.releaseType == 'RELEASE' ? ['mavenSyncRepoDir'] : ['s3AccessKey', 's3SecretAccessKey']
|
|
checkForProps(taskPath: project.path + ':uploadArchives', requiredProps: requiredProps)
|
|
|
|
/**
|
|
* Builds a source jar artifact for all main java sources.
|
|
*
|
|
* @author Luke Taylor
|
|
*/
|
|
task sourceJar(type: Jar) {
|
|
description = 'Builds a source jar artifact suitable for maven deployment.'
|
|
classifier = 'sources'
|
|
from sourceSets.main.java
|
|
}
|
|
build.dependsOn sourceJar
|
|
|
|
jar.destinationDir = project.libsBinDir
|
|
sourceJar.destinationDir = project.libsSrcDir
|
|
|
|
// Add the source jar archive to the set of artifacts for this project.
|
|
// Note that the regular 'jar' archive is already added by default.
|
|
artifacts {
|
|
archives sourceJar
|
|
}
|
|
|
|
|
|
/**
|
|
* Deploy gradle-built artifacts to a remote maven repository. Overrides and
|
|
* further customizes the 'uploadArchives' task contributed by the 'maven'
|
|
* plugin.
|
|
*
|
|
* The repository that artifacts are deployed to is determined conditionally
|
|
* based on the release type of the project version. Snapshot builds will
|
|
* be deployed via s3 to the springframework maven snapshot repository;
|
|
* milestone builds will happen via s3 as well; release builds will be deployed
|
|
* to the local filesystem to be sync'd via sourceforge SVN and ultimately
|
|
* deployed to maven central.
|
|
*
|
|
* Gradle will generate Maven poms on-the-fly during the deployment process.
|
|
* This process is customized to add ASL license information, and for projects
|
|
* that have the erlangLicense property set to true, the Erlang License will be
|
|
* added to the pom as well.
|
|
*
|
|
* @author Chris Beams
|
|
* @see 'mavenSyncRepoDir' in gradle.properties
|
|
* @see `gradle install` for deploying artifacts to the local .m2 cache
|
|
* @see http://maven.apache.org/guides/mini/guide-central-repository-upload.html
|
|
*/
|
|
uploadArchives {
|
|
group = 'Buildmaster'
|
|
description = "Does a maven deploy of archives artifacts to " // url appended below
|
|
|
|
def releaseRepositoryUrl = "file://${project.properties.mavenSyncRepoDir}"
|
|
def milestoneRepositoryUrl = 's3://maven.springframework.org/milestone'
|
|
def snapshotRepositoryUrl = 's3://maven.springframework.org/snapshot'
|
|
|
|
// add a configuration with a classpath that includes our s3 maven deployer
|
|
configurations { deployerJars }
|
|
dependencies {
|
|
deployerJars "org.springframework.build.aws:org.springframework.build.aws.maven:3.0.0.RELEASE"
|
|
}
|
|
|
|
def deployer = repositories.mavenDeployer {
|
|
switch (version.releaseType) {
|
|
case 'RELEASE':
|
|
repository(url: releaseRepositoryUrl)
|
|
description += releaseRepositoryUrl
|
|
break;
|
|
|
|
case 'MILESTONE':
|
|
description += milestoneRepositoryUrl
|
|
s3credentials = [userName: project.properties.s3AccessKey, passphrase: project.properties.s3SecretAccessKey]
|
|
configuration = configurations.deployerJars
|
|
repository(url: milestoneRepositoryUrl) {
|
|
authentication(s3credentials)
|
|
}
|
|
snapshotRepository(url: snapshotRepositoryUrl) {
|
|
authentication(s3credentials)
|
|
}
|
|
break;
|
|
|
|
case 'SNAPSHOT':
|
|
description += snapshotRepositoryUrl
|
|
s3credentials = [userName: project.properties.s3AccessKey, passphrase: project.properties.s3SecretAccessKey]
|
|
configuration = configurations.deployerJars
|
|
repository(url: milestoneRepositoryUrl) {
|
|
authentication(s3credentials)
|
|
}
|
|
snapshotRepository(url: snapshotRepositoryUrl) {
|
|
authentication(s3credentials)
|
|
}
|
|
break;
|
|
|
|
default:
|
|
throw new GradleException("unknown ReleaseType")
|
|
}
|
|
}
|
|
|
|
configurePom(deployer.pom)
|
|
}
|
|
|
|
|
|
/**
|
|
* Install gradle-built artifacts to the local m2 maven cache.
|
|
* Further customizes the 'install' task contributed by the 'maven' plugin.
|
|
*/
|
|
install {
|
|
group = 'Build'
|
|
description = "Does a maven install of archives artifacts to local m2 cache"
|
|
|
|
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 ->
|
|
gradleDep.asDynamicObject.hasProperty('optional') && gradleDep.optional
|
|
}
|
|
def providedDeps = configurations.testRuntime.allDependencies.findAll { gradleDep ->
|
|
gradleDep.asDynamicObject.hasProperty('provided') && gradleDep.provided
|
|
}
|
|
generatedPom.dependencies.each { mavenDep ->
|
|
mavenDep.optional = optionalDeps.any { optionalDep ->
|
|
optionalDep.group == mavenDep.groupId &&
|
|
optionalDep.name == mavenDep.artifactId &&
|
|
optionalDep.version == mavenDep.version
|
|
}
|
|
boolean isProvided = providedDeps.any { providedDep ->
|
|
providedDep.group == mavenDep.groupId &&
|
|
providedDep.name == mavenDep.artifactId &&
|
|
providedDep.version == mavenDep.version
|
|
}
|
|
if (isProvided) {
|
|
mavenDep.scope = 'provided'
|
|
}
|
|
}
|
|
}
|
|
|
|
pom.project {
|
|
licenses {
|
|
license {
|
|
name 'The Apache Software License, Version 2.0'
|
|
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
|
distribution 'repo'
|
|
}
|
|
}
|
|
}
|
|
}
|