问题
I'm creating gradle builds as a new gradle user, but I have worked with maven in the past.
I'm trying to reproduce actions of the maven release plugin:
- Change branch version to Release number (commit at svn)
- Create a tag (at svn)
- Deploy the release tag in Nexus OSS
- Change branch version to new Snapshot number (commit at svn)
As you can see, I'm using:
- Nexus OSS as versioning repository
- SVN as scm
- Gradle (2.8)
I'm trying to achieve my objectives with these two plugins:
Gradle-release Plugin:
- Change branch version to Release number (commit at svn)
- Create a tag (at svn)
- Change branch version to new Snapshot number (commit at svn)
Command line: gradle release
Maven Publish Plugin to deploy to Nexus:
Command line: gradle publish
Any ideas how I could generate a release and automatically deploy it to Nexus in one shot?
Below is my build.gradle:
plugins {
id 'net.researchgate.release' version '2.3.4'
}
apply plugin: 'maven-publish'
/*------------------------
----- PUBLISH PLUGIN -----
--------------------------
https://docs.gradle.org/current/userguide/publishing_maven.html
--------------------------*/
publishing {
publications {
maven(MavenPublication) {
groupId mavenGroup
artifactId mavenArtifact
version version
from components.java
}
}
repositories {
maven {
if(project.version.endsWith('-SNAPSHOT')) {
url "${nexusUrl}/content/repositories/repo-snapshots"
} else {
url "${nexusUrl}/content/repositories/repo-releases"
}
credentials {
username nexusUsername
password nexusPassword
}
}
}
}
/*------------------------
----- RELEASE PLUGIN -----
--------------------------
https://github.com/researchgate/gradle-release
--------------------------*/
release {
failOnCommitNeeded = false
failOnUnversionedFiles = false
scmAdapters = [
net.researchgate.release.SvnAdapter
]
}
回答1:
You need to setup a dependency between the two tasks. This can be done by adding this line in your build.gradle
:
afterReleaseBuild.dependsOn publish
The release-plugin has two tasks which are exactly for the usecase of hooking other tasks in the release process, namely beforeReleaseBuild
and afterReleaseBuild
. This tasks (and the dependencies you set) are executed before or respectively after the build
task.
https://github.com/researchgate/gradle-release#custom-release-steps
来源:https://stackoverflow.com/questions/33867323/gradle-release-plugin-maven-publishing-plugin