Skip to content

Commit

Permalink
Upgrading release process
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Ryan committed Apr 2, 2013
1 parent 63e44e8 commit 8caf8ec
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 80 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ ext.githubProjectName = rootProject.name // Change if github project name is not
buildscript {
repositories {
mavenLocal()
maven { url 'http://jcenter.bintray.com' }
mavenCentral() // maven { url 'http://jcenter.bintray.com' }
}
apply from: file('gradle/buildscript.gradle'), to: buildscript
}

allprojects {
repositories { mavenRepo url: 'http://jcenter.bintray.com' }
repositories {
mavenCentral() // maven { url: 'http://jcenter.bintray.com' }
}
}

apply from: file('gradle/convention.gradle')
Expand Down
2 changes: 1 addition & 1 deletion gradle/buildscript.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ repositories {
dependencies {
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.6.1'
classpath 'com.mapvine:gradle-cobertura-plugin:0.1'
classpath 'gradle-release:gradle-release:1.1'
classpath 'gradle-release:gradle-release:1.1.4'
}
41 changes: 21 additions & 20 deletions gradle/check.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
subprojects {
// Checkstyle
apply plugin: 'checkstyle'
tasks.withType(Checkstyle) { ignoreFailures = true }
checkstyle {
ignoreFailures = true // Waiting on GRADLE-2163
configFile = rootProject.file('codequality/checkstyle.xml')
}
// Checkstyle
apply plugin: 'checkstyle'
checkstyle {
ignoreFailures = true
configFile = rootProject.file('codequality/checkstyle.xml')
}

// FindBugs
apply plugin: 'findbugs'
//tasks.withType(Findbugs) { reports.html.enabled true }
// FindBugs
apply plugin: 'findbugs'
findbugs {
ignoreFailures = true
}

// PMD
apply plugin: 'pmd'
//tasks.withType(Pmd) { reports.html.enabled true }
// PMD
apply plugin: 'pmd'
//tasks.withType(Pmd) { reports.html.enabled true }

apply plugin: 'cobertura'
cobertura {
sourceDirs = sourceSets.main.java.srcDirs
format = 'html'
includes = ['**/*.java', '**/*.groovy']
excludes = []
}
apply plugin: 'cobertura'
cobertura {
sourceDirs = sourceSets.main.java.srcDirs
format = 'html'
includes = ['**/*.java', '**/*.groovy']
excludes = []
}
}
13 changes: 3 additions & 10 deletions gradle/convention.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@

// For Artifactory
rootProject.status = version.contains('-SNAPSHOT')?'snapshot':'release'
status = version.contains('SNAPSHOT')?'snapshot':status

subprojects { project ->
apply plugin: 'java' // Plugin as major conventions

version = rootProject.version

sourceCompatibility = 1.6

// GRADLE-2087 workaround, perform after java plugin
// Restore status after Java plugin
status = rootProject.status

task sourcesJar(type: Jar, dependsOn:classes) {
Expand Down Expand Up @@ -51,9 +47,6 @@ subprojects { project ->
}
}

// Ensure output is on a new line
javadoc.doFirst { println "" }

configurations {
provided {
description = 'much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive.'
Expand All @@ -79,5 +72,5 @@ task aggregateJavadoc(type: Javadoc) {

// Generate wrapper, which is distributed as part of source to alleviate the need of installing gradle
task createWrapper(type: Wrapper) {
gradleVersion = '1.4'
gradleVersion = '1.5'
}
19 changes: 10 additions & 9 deletions gradle/maven.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ subprojects {
sign configurations.archives
}

/**
* Publishing to Maven Central example provided from http://jedicoder.blogspot.com/2011/11/automated-gradle-project-deployment-to.html
*/
task uploadMavenCentral(type:Upload, dependsOn: signArchives) {
configuration = configurations.archives
doFirst {
repositories.mavenDeployer {
beforeDeployment { org.gradle.api.artifacts.maven.MavenDeployment deployment -> signing.signPom(deployment) }
/**
* Publishing to Maven Central example provided from http://jedicoder.blogspot.com/2011/11/automated-gradle-project-deployment-to.html
* artifactory will execute uploadArchives to force generation of ivy.xml, and we don't want that to trigger an upload to maven
* central, so using custom upload task.
*/
task uploadMavenCentral(type:Upload, dependsOn: signArchives) {
configuration = configurations.archives
onlyIf { ['release', 'snapshot'].contains(project.status) }
repositories.mavenDeployer {
beforeDeployment { signing.signPom(it) }

// To test deployment locally, use the following instead of oss.sonatype.org
//repository(url: "file://localhost/${rootProject.rootDir}/repo")
Expand Down Expand Up @@ -62,5 +64,4 @@ subprojects {
}
}
}
}
}
71 changes: 33 additions & 38 deletions gradle/release.gradle
Original file line number Diff line number Diff line change
@@ -1,60 +1,55 @@
apply plugin: 'release'

// Ignore release plugin's task because it calls out via GradleBuild. This is a good place to put an email to send out
task release(overwrite: true, dependsOn: commitNewVersion) << {
// This is a good place to put an email to send out
}
commitNewVersion.dependsOn updateVersion
updateVersion.dependsOn createReleaseTag
createReleaseTag.dependsOn preTagCommit
preTagCommit.dependsOn build
preTagCommit.dependsOn buildWithArtifactory
preTagCommit.dependsOn checkSnapshotDependencies
checkSnapshotDependencies.dependsOn confirmReleaseVersion
confirmReleaseVersion.dependsOn unSnapshotVersion
unSnapshotVersion.dependsOn checkUpdateNeeded
checkUpdateNeeded.dependsOn checkCommitNeeded
checkCommitNeeded.dependsOn initScmPlugin

[
uploadIvyLocal: 'uploadLocal',
uploadArtifactory: 'artifactoryPublish', // Call out to compile against internal repository
buildWithArtifactory: 'build' // Build against internal repository
].each { key, value ->
[ uploadIvyLocal: 'uploadLocal', uploadArtifactory: 'artifactoryPublish', buildWithArtifactory: 'build' ].each { key, value ->
// Call out to compile against internal repository
task "${key}"(type: GradleBuild) {
startParameter = project.gradle.startParameter.newInstance()
doFirst {
startParameter.projectProperties = [status: project.status]
}
startParameter.addInitScript( file('gradle/netflix-oss.gradle') )
startParameter.getExcludedTaskNames().add('check')
tasks = [ 'build', value ]
}
}
task releaseArtifactory(dependsOn: [preTagCommit, uploadArtifactory])

// Marker task for following code to key in on
task releaseCandidate(dependsOn: release)
task forceCandidate {
onlyIf { gradle.taskGraph.hasTask(releaseCandidate) }
doFirst { project.status = 'candidate' }
}
release.dependsOn(forceCandidate)

task releaseSnapshot(dependsOn: [uploadArtifactory, uploadMavenCentral])

// Ensure our versions look like the project status before publishing
task verifyStatus << {
def hasSnapshot = version.contains('-SNAPSHOT')
if (project.status == 'snapshot' && !hasSnapshot) {
throw new GradleException("Version (${version}) needs -SNAPSHOT if publishing snapshot")
}
}
uploadArtifactory.dependsOn(verifyStatus)
uploadMavenCentral.dependsOn(verifyStatus)

// Ensure upload happens before taggging but after all pre-checks
createReleaseTag.dependsOn releaseArtifactory
createReleaseTag.dependsOn([uploadArtifactory, uploadMavenCentral])

subprojects.each { project ->
project.uploadMavenCentral.dependsOn rootProject.preTagCommit
rootProject.createReleaseTag.dependsOn project.uploadMavenCentral
gradle.taskGraph.whenReady { taskGraph ->
def hasRelease = taskGraph.hasTask('commitNewVersion')
def indexOf = { return taskGraph.allTasks.indexOf(it) }

gradle.taskGraph.whenReady { taskGraph ->
if ( rootProject.status == 'release' && !taskGraph.hasTask(':release') ) {
throw new GradleException('"release" task has to be run before uploading a release')
}
if (hasRelease) {
assert indexOf(build) < indexOf(unSnapshotVersion), 'build target has to be after unSnapshotVersion'
assert indexOf(uploadMavenCentral) < indexOf(preTagCommit), 'preTagCommit has to be after uploadMavenCentral'
assert indexOf(uploadArtifactory) < indexOf(preTagCommit), 'preTagCommit has to be after uploadArtifactory'
}
}

// Prevent plugin from asking for a version number interactively
ext.'gradle.release.useAutomaticVersion' = "true"

release {
failOnCommitNeeded=true
failOnPublishNeeded=true
failOnSnapshotDependencies=true
failOnUnversionedFiles=true
failOnUpdateNeeded=true
includeProjectNameInTag=true
revertOnFail=true
requireBranch = null
git.requireBranch = null
}

0 comments on commit 8caf8ec

Please sign in to comment.