diff --git a/README.md b/README.md index ab0e9dd..726b149 100644 --- a/README.md +++ b/README.md @@ -82,12 +82,41 @@ group = 'org.example' publishing { [...] } -tasks.release { - dependsOn build - finalizedBy publish +``` + +There is a new `release` task, which automatically dependsOn the `build` task and is finalizedBy the `publish` task +(and the `uploadArchives` task, if you use the old publishing mechanism). + +### Uploading SNAPSHOT and releases to different repositories + +Because the `release` task does automatically execute the `publish` task, you must take care of configuring only valid +repositories. + +```groovy +publishing { + repositories { + maven { + if (version.toString().endsWith("-SNAPSHOT") { + url "http://.../snapshots" + } else { + url "http://.../releases" + } + } + } } ``` +### Uploading using other plugins + +If you need other mechanisms to upload your artifacts, you need to manually configure this. + +```groovy +if (!version.toString().endsWith('-SNAPSHOT')) + publish.dependsOn publishPlugins, bintrayUpload +else if ((System.getenv('TRAVIS_PULL_REQUEST') ?: "false") == "false") + publish.dependsOn artifactoryPublish +``` + ### Enable upload of the changelog to GitHub In order to automatically upload the changelog to GitHub, you need a [GitHub token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) and tell the plugin about it. diff --git a/build.gradle b/build.gradle index 668241f..488fb97 100644 --- a/build.gradle +++ b/build.gradle @@ -54,10 +54,10 @@ task integTest { dependsOn test } -tasks.release { - dependsOn build - finalizedBy publishPlugins, bintrayUpload, artifactoryPublish -} +if (!version.toString().endsWith('-SNAPSHOT')) + publish.dependsOn publishPlugins, bintrayUpload +else if ((System.getenv('TRAVIS_PULL_REQUEST') ?: "false") == "false") + publish.dependsOn artifactoryPublish test { if (gradle.startParameter.taskNames.find { ['integTest', 'release'].contains(it) }) diff --git a/gradle/artifactory.gradle b/gradle/artifactory.gradle index 583d9f6..69e324a 100644 --- a/gradle/artifactory.gradle +++ b/gradle/artifactory.gradle @@ -21,11 +21,3 @@ artifactory { } } - -artifactoryPublish { - onlyIf { - def pullRequest = System.getenv('TRAVIS_PULL_REQUEST') - - project.version.toString().endsWith('-SNAPSHOT') && (!pullRequest || pullRequest=='false') - } -} diff --git a/gradle/bintray.gradle b/gradle/bintray.gradle index 85f2725..62702b2 100644 --- a/gradle/bintray.gradle +++ b/gradle/bintray.gradle @@ -25,9 +25,3 @@ bintray { } } } - -bintrayUpload { - onlyIf { - !project.version.toString().endsWith('-SNAPSHOT') - } -} diff --git a/gradle/publish-plugin.gradle b/gradle/publish-plugin.gradle index 8973286..1656fff 100644 --- a/gradle/publish-plugin.gradle +++ b/gradle/publish-plugin.gradle @@ -13,9 +13,3 @@ pluginBundle { } } } - -tasks.publishPlugins { - onlyIf { - !project.version.toString().endsWith('-SNAPSHOT') - } -} diff --git a/src/main/groovy/de/gliderpilot/gradle/semanticrelease/SemanticReleasePlugin.groovy b/src/main/groovy/de/gliderpilot/gradle/semanticrelease/SemanticReleasePlugin.groovy index 7ad8e4b..22f24f4 100644 --- a/src/main/groovy/de/gliderpilot/gradle/semanticrelease/SemanticReleasePlugin.groovy +++ b/src/main/groovy/de/gliderpilot/gradle/semanticrelease/SemanticReleasePlugin.groovy @@ -18,6 +18,9 @@ package de.gliderpilot.gradle.semanticrelease import org.ajoberstar.gradle.git.release.base.ReleasePluginExtension import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.plugins.BasePlugin +import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.publish.plugins.PublishingPlugin class SemanticReleasePlugin implements Plugin { @@ -27,7 +30,8 @@ class SemanticReleasePlugin implements Plugin { plugins.apply(org.ajoberstar.gradle.git.release.base.BaseReleasePlugin) SemanticReleasePluginExtension semanticReleaseExtension = extensions.create("semanticRelease", SemanticReleasePluginExtension, project) ReleasePluginExtension releaseExtension = extensions.findByType(ReleasePluginExtension) - tasks.release.doLast { + def releaseTask = tasks.release + releaseTask.doLast { if (project.version.inferredVersion.createTag) { semanticReleaseExtension.changeLog.createGitHubVersion(project.version.inferredVersion) } @@ -36,6 +40,17 @@ class SemanticReleasePlugin implements Plugin { versionStrategy semanticReleaseExtension.releaseStrategy defaultVersionStrategy = semanticReleaseExtension.snapshotStrategy } + allprojects { prj -> + prj.plugins.withType(JavaBasePlugin) { + releaseTask.dependsOn prj.tasks.build + } + prj.plugins.withType(BasePlugin) { + releaseTask.finalizedBy prj.tasks.uploadArchives + } + prj.plugins.withType(PublishingPlugin) { + releaseTask.finalizedBy prj.tasks.publish + } + } } } } diff --git a/src/test/groovy/de/gliderpilot/gradle/semanticrelease/SemanticReleasePluginSpec.groovy b/src/test/groovy/de/gliderpilot/gradle/semanticrelease/SemanticReleasePluginSpec.groovy index 672a0de..0da5e6b 100644 --- a/src/test/groovy/de/gliderpilot/gradle/semanticrelease/SemanticReleasePluginSpec.groovy +++ b/src/test/groovy/de/gliderpilot/gradle/semanticrelease/SemanticReleasePluginSpec.groovy @@ -152,4 +152,18 @@ class SemanticReleasePluginSpec extends ProjectSpec { project.semanticRelease.branchNames.replacePatterns.foo == 'bar' } + def "autowires release task dependencies"() { + when: + project.with { + apply plugin: PLUGIN + apply plugin: 'java' + apply plugin: 'maven-publish' + } + + then: + project.tasks.release.dependsOn.contains(project.tasks.build) + project.tasks.release.finalizedBy.getDependencies(project.tasks.release).contains(project.tasks.publish) + project.tasks.release.finalizedBy.getDependencies(project.tasks.release).contains(project.tasks.uploadArchives) + } + }