首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Gradle中使用一个版本和标记发布多模块项目

在Gradle中使用一个版本和标记发布多模块项目
EN

Stack Overflow用户
提问于 2016-09-13 13:02:54
回答 1查看 1.9K关注 0票数 4

我在Gradle中有多模块项目,其中父build.gradle只是子项目的聚合器,没有任何来源。

结构:

代码语言:javascript
运行
复制
parent with version in gradle.properties
 - child1 inheriting version
 - child2 inheriting version

两个孩子都生产带有工件的罐子,而父母则生产空罐子,我根本不想上传这些罐子。

现在我想发布这样的项目。在Git中应该有一个版本更新和一个标记。但是,所有的子项目都应该构建并上传到存储库中。我怎样才能实现它?

我尝试过分级发布插件,但是我很难正确地配置它。我得到以下任何一种:

  • 将插件应用于父级,得到正确的提交和标记,但只上传根项目。
  • 在子项目上应用插件,正确上传项目,但对每个子项目有单独的提交和标记
EN

回答 1

Stack Overflow用户

发布于 2016-10-04 17:16:50

我也有同样的问题,在Gradle - steps插件(https://github.com/martoe/gradle-svntools-plugin)的帮助下,我在gradle中编写了必要的步骤。请注意,我不是Groovy专家,所以我想一些事情可以更容易地完成:)

我在父项目中的build.gradle:

代码语言:javascript
运行
复制
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'at.bxm.gradleplugins:gradle-svntools-plugin:1.6.2'
    }
}

allprojects {
    apply plugin: 'at.bxm.svntools'

    //subversion login
    svntools {
        username = svnUsername
        password = credentials.svnpwd
    }
}

//task to write the version parameter given via command line into the  "gradle.properties" files.
// Call with: gradle writeProjectVersion -PnewVersion=1.0.1-SNAPSHOT
task('writeProjectVersion') << {
    if (project.hasProperty('newVersion')) {
        //set version in gradle settings
        project.version = project.newVersion
        project.subprojects?.each {it.version = project.version }
        //set version in all the gradle.properties files
        new File(".").traverse(type : groovy.io.FileType.FILES, nameFilter: 'gradle.properties') {
            project.ant.replaceregexp(file: it, byline: true) {
                key = 'version'
                version = project.version
                regexp(pattern: "^(\\s*)$key((\\s*[=|:]\\s*)|(\\s+)).+\$")
                substitution(expression: "\\1$key\\2$version")
            }
        }
        println 'Successfully changed project version in gradle.properties to \'' + project.version + '\''
    } else {
        println 'No parameter \'newVersion\' provided, so not changing the project version.'
    }
}


//task to commit the gradle.properties changes into SVN - also needs the new version as parameter for the commit message
// Call with: gradle svnCommit -PnewVersion=1.0.1-SNAPSHOT
task('svnCommit', type: at.bxm.gradleplugins.svntools.tasks.SvnCommit) {
    if (project.hasProperty('newVersion')) {
        def files = []
        new File(".").traverse(type : groovy.io.FileType.FILES, nameFilter: 'gradle.properties') { files << it } //appends all matching files to the list
        source = files
        commitMessage = "[Jenkins Release Build] Changing project version to '" + project.newVersion + "'"
    } else {
        println 'No parameter \'newVersion\' provided, so SVN commit was not executed.'
    }
}

//task to tag the current head - also needs the new version as parameter for the commit message
// Call with: gradle svnTag -PnewVersion=1.0.1-SNAPSHOT
task('svnTag', type: at.bxm.gradleplugins.svntools.tasks.SvnTag) {
    if (project.hasProperty('newVersion')) {
        tagName = "$project.newVersion"
        localChanges = true
        commitMessage = "[Jenkins Release Build] Tagging Release version $project.newVersion"
    } else {
        println 'No parameter \'newVersion\' provided, so SVN tagging was not executed.'
    }
}

我使用Jenkins执行并运行以下shell脚本:

代码语言:javascript
运行
复制
# execute gradle tests
gradle test
# set version in gradle.properties and tag the current code (gradle.properties changes are commited in the tag)
gradle writeProjectVersion -PnewVersion=${releaseVersion}
gradle svnTag -PnewVersion=${releaseVersion}
# build the artifacts and upload them to Nexus without running the test cases again
gradle clean build uploadArchives -x test
# set version in gradle.properties and commit the files
gradle writeProjectVersion -PnewVersion=${newSnapshotVersion}
gradle svnCommit -PnewVersion=${newSnapshotVersion}

希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39470809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档