gradle-release plugin + maven publishing plugin

大憨熊 提交于 2020-01-01 04:49:09

问题


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:

  1. 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

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!