Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
281 lines (250 sloc) 10.8 KB
/*
* 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
apply from: "$rootDir/buildSrc/preconditions.gradle"
def requiredProps = ['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 's3AccessKey' in gradle.properties
* @see 's3SecretAccessKey' 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
// 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"
}
// bring up a deployer and push to the appropriate repo for this release type
// note that repository and snapshotRepository are the same - it doesn't matter
// if it is actually a BUILD-SNAPSHOT, the snapshotRepository will kick in,
// otherwise it is ignored.
repositories.mavenDeployer { deployer ->
def repositoryUrl = 's3://maven.springframework.org/' + version.releaseType.toString().toLowerCase()
description += repositoryUrl
configuration = configurations.deployerJars
s3credentials = [userName: project.properties.s3AccessKey,
passphrase: project.properties.s3SecretAccessKey]
repository(url: repositoryUrl) { authentication(s3credentials) }
snapshotRepository(url: repositoryUrl) { authentication(s3credentials) }
configurePom(deployer.pom)
}
if (version.releaseType == 'RELEASE') {
// we're dealing with a GA release (RELEASE), so bring up a second
// maven deployer and deploy to the maven sync repository filesystem
// location. The SVN commit must be done manually after the build.
repositories.mavenDeployer { deployer ->
repository(url: "file://${project.properties.mavenSyncRepoDir}")
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"
// ensure changes in the classpath trigger regeneration of poms
inputs.files(project.sourceSets.main.compileClasspath)
// ensure version changes in gradle.properties trigger regeneration of poms
inputs.files(new File(project.rootProject.rootDir, Project.GRADLE_PROPERTIES))
// 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')
}
// iterate through all repositories declared in the gradle
// script(s) and render each in the generated pom
repositories {
project.repositories.each { repo ->
if (repo.name == 'MavenRepo') {
// do not include the Maven Central repository
return
}
repository {
id = repo.name
url = repo.root
}
}
}
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'
}
}
}
}
Something went wrong with that request. Please try again.