apply plugin: 'release' [ 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, preferredStatus: project.status] } startParameter.addInitScript( file('gradle/netflix-oss.gradle') ) startParameter.getExcludedTaskNames().add('check') tasks = [ 'build', value ] } } // Marker task for following code to key in on task releaseCandidate(dependsOn: release) task forceCandidate { onlyIf { gradle.taskGraph.hasTask(releaseCandidate) } doFirst { project.status = 'candidate' } } task forceRelease { onlyIf { !gradle.taskGraph.hasTask(releaseCandidate) } doFirst { project.status = 'release' } } release.dependsOn([forceCandidate, forceRelease]) task uploadMavenCentral(dependsOn: subprojects.tasks.uploadMavenCentral) 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, hence upload failures will leave repo in a revertable state preTagCommit.dependsOn([uploadArtifactory, uploadMavenCentral]) gradle.taskGraph.whenReady { taskGraph -> def hasRelease = taskGraph.hasTask('commitNewVersion') def indexOf = { return taskGraph.allTasks.indexOf(it) } 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 { git.requireBranch = null }