Skip to content

Commit 8caf8ec

Browse files
author
Justin Ryan
committed
Upgrading release process
1 parent 63e44e8 commit 8caf8ec

File tree

6 files changed

+72
-80
lines changed

6 files changed

+72
-80
lines changed

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ ext.githubProjectName = rootProject.name // Change if github project name is not
44
buildscript {
55
repositories {
66
mavenLocal()
7-
maven { url 'http://jcenter.bintray.com' }
7+
mavenCentral() // maven { url 'http://jcenter.bintray.com' }
88
}
99
apply from: file('gradle/buildscript.gradle'), to: buildscript
1010
}
1111

1212
allprojects {
13-
repositories { mavenRepo url: 'http://jcenter.bintray.com' }
13+
repositories {
14+
mavenCentral() // maven { url: 'http://jcenter.bintray.com' }
15+
}
1416
}
1517

1618
apply from: file('gradle/convention.gradle')

gradle/buildscript.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ repositories {
66
dependencies {
77
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.6.1'
88
classpath 'com.mapvine:gradle-cobertura-plugin:0.1'
9-
classpath 'gradle-release:gradle-release:1.1'
9+
classpath 'gradle-release:gradle-release:1.1.4'
1010
}

gradle/check.gradle

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
subprojects {
2-
// Checkstyle
3-
apply plugin: 'checkstyle'
4-
tasks.withType(Checkstyle) { ignoreFailures = true }
5-
checkstyle {
6-
ignoreFailures = true // Waiting on GRADLE-2163
7-
configFile = rootProject.file('codequality/checkstyle.xml')
8-
}
2+
// Checkstyle
3+
apply plugin: 'checkstyle'
4+
checkstyle {
5+
ignoreFailures = true
6+
configFile = rootProject.file('codequality/checkstyle.xml')
7+
}
98

10-
// FindBugs
11-
apply plugin: 'findbugs'
12-
//tasks.withType(Findbugs) { reports.html.enabled true }
9+
// FindBugs
10+
apply plugin: 'findbugs'
11+
findbugs {
12+
ignoreFailures = true
13+
}
1314

14-
// PMD
15-
apply plugin: 'pmd'
16-
//tasks.withType(Pmd) { reports.html.enabled true }
15+
// PMD
16+
apply plugin: 'pmd'
17+
//tasks.withType(Pmd) { reports.html.enabled true }
1718

18-
apply plugin: 'cobertura'
19-
cobertura {
20-
sourceDirs = sourceSets.main.java.srcDirs
21-
format = 'html'
22-
includes = ['**/*.java', '**/*.groovy']
23-
excludes = []
24-
}
19+
apply plugin: 'cobertura'
20+
cobertura {
21+
sourceDirs = sourceSets.main.java.srcDirs
22+
format = 'html'
23+
includes = ['**/*.java', '**/*.groovy']
24+
excludes = []
25+
}
2526
}

gradle/convention.gradle

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
2-
// For Artifactory
3-
rootProject.status = version.contains('-SNAPSHOT')?'snapshot':'release'
1+
status = version.contains('SNAPSHOT')?'snapshot':status
42

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

8-
version = rootProject.version
9-
106
sourceCompatibility = 1.6
117

12-
// GRADLE-2087 workaround, perform after java plugin
8+
// Restore status after Java plugin
139
status = rootProject.status
1410

1511
task sourcesJar(type: Jar, dependsOn:classes) {
@@ -51,9 +47,6 @@ subprojects { project ->
5147
}
5248
}
5349

54-
// Ensure output is on a new line
55-
javadoc.doFirst { println "" }
56-
5750
configurations {
5851
provided {
5952
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.'
@@ -79,5 +72,5 @@ task aggregateJavadoc(type: Javadoc) {
7972

8073
// Generate wrapper, which is distributed as part of source to alleviate the need of installing gradle
8174
task createWrapper(type: Wrapper) {
82-
gradleVersion = '1.4'
75+
gradleVersion = '1.5'
8376
}

gradle/maven.gradle

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ subprojects {
88
sign configurations.archives
99
}
1010

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

2022
// To test deployment locally, use the following instead of oss.sonatype.org
2123
//repository(url: "file://localhost/${rootProject.rootDir}/repo")
@@ -62,5 +64,4 @@ subprojects {
6264
}
6365
}
6466
}
65-
}
6667
}

gradle/release.gradle

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,55 @@
11
apply plugin: 'release'
22

3-
// Ignore release plugin's task because it calls out via GradleBuild. This is a good place to put an email to send out
4-
task release(overwrite: true, dependsOn: commitNewVersion) << {
5-
// This is a good place to put an email to send out
6-
}
7-
commitNewVersion.dependsOn updateVersion
8-
updateVersion.dependsOn createReleaseTag
9-
createReleaseTag.dependsOn preTagCommit
10-
preTagCommit.dependsOn build
11-
preTagCommit.dependsOn buildWithArtifactory
12-
preTagCommit.dependsOn checkSnapshotDependencies
13-
checkSnapshotDependencies.dependsOn confirmReleaseVersion
14-
confirmReleaseVersion.dependsOn unSnapshotVersion
15-
unSnapshotVersion.dependsOn checkUpdateNeeded
16-
checkUpdateNeeded.dependsOn checkCommitNeeded
17-
checkCommitNeeded.dependsOn initScmPlugin
18-
19-
[
20-
uploadIvyLocal: 'uploadLocal',
21-
uploadArtifactory: 'artifactoryPublish', // Call out to compile against internal repository
22-
buildWithArtifactory: 'build' // Build against internal repository
23-
].each { key, value ->
3+
[ uploadIvyLocal: 'uploadLocal', uploadArtifactory: 'artifactoryPublish', buildWithArtifactory: 'build' ].each { key, value ->
244
// Call out to compile against internal repository
255
task "${key}"(type: GradleBuild) {
266
startParameter = project.gradle.startParameter.newInstance()
7+
doFirst {
8+
startParameter.projectProperties = [status: project.status]
9+
}
2710
startParameter.addInitScript( file('gradle/netflix-oss.gradle') )
2811
startParameter.getExcludedTaskNames().add('check')
2912
tasks = [ 'build', value ]
3013
}
3114
}
32-
task releaseArtifactory(dependsOn: [preTagCommit, uploadArtifactory])
15+
16+
// Marker task for following code to key in on
17+
task releaseCandidate(dependsOn: release)
18+
task forceCandidate {
19+
onlyIf { gradle.taskGraph.hasTask(releaseCandidate) }
20+
doFirst { project.status = 'candidate' }
21+
}
22+
release.dependsOn(forceCandidate)
23+
24+
task releaseSnapshot(dependsOn: [uploadArtifactory, uploadMavenCentral])
25+
26+
// Ensure our versions look like the project status before publishing
27+
task verifyStatus << {
28+
def hasSnapshot = version.contains('-SNAPSHOT')
29+
if (project.status == 'snapshot' && !hasSnapshot) {
30+
throw new GradleException("Version (${version}) needs -SNAPSHOT if publishing snapshot")
31+
}
32+
}
33+
uploadArtifactory.dependsOn(verifyStatus)
34+
uploadMavenCentral.dependsOn(verifyStatus)
3335

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

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

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

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

5153
release {
52-
failOnCommitNeeded=true
53-
failOnPublishNeeded=true
54-
failOnSnapshotDependencies=true
55-
failOnUnversionedFiles=true
56-
failOnUpdateNeeded=true
57-
includeProjectNameInTag=true
58-
revertOnFail=true
59-
requireBranch = null
54+
git.requireBranch = null
6055
}

0 commit comments

Comments
 (0)