Skip to content

Commit

Permalink
feat: autowire build and upload tasks to release
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
tschulte committed Aug 10, 2016
1 parent 906c37d commit 8ba51eb
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 28 deletions.
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down
8 changes: 0 additions & 8 deletions gradle/artifactory.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,3 @@ artifactory {
}

}

artifactoryPublish {
onlyIf {
def pullRequest = System.getenv('TRAVIS_PULL_REQUEST')

project.version.toString().endsWith('-SNAPSHOT') && (!pullRequest || pullRequest=='false')
}
}
6 changes: 0 additions & 6 deletions gradle/bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,3 @@ bintray {
}
}
}

bintrayUpload {
onlyIf {
!project.version.toString().endsWith('-SNAPSHOT')
}
}
6 changes: 0 additions & 6 deletions gradle/publish-plugin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@ pluginBundle {
}
}
}

tasks.publishPlugins {
onlyIf {
!project.version.toString().endsWith('-SNAPSHOT')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {

Expand All @@ -27,7 +30,8 @@ class SemanticReleasePlugin implements Plugin<Project> {
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)
}
Expand All @@ -36,6 +40,17 @@ class SemanticReleasePlugin implements Plugin<Project> {
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

This comment has been minimized.

Copy link
@weisebrazil

weisebrazil Aug 16, 2016

Contributor

When I configure java plugin, it adds BasePlugin too. So, my project causes error because I only use maven-publish.
JavaBasePlugin:93
Gradle Upload

}
prj.plugins.withType(PublishingPlugin) {
releaseTask.finalizedBy prj.tasks.publish
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}

0 comments on commit 8ba51eb

Please sign in to comment.