gpt4 book ai didi

gradle - 在 Gradle 中使用一个版本和标签发布多模块项目

转载 作者:行者123 更新时间:2023-12-01 15:20:38 25 4
gpt4 key购买 nike

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

结构:

parent with version in gradle.properties
- child1 inheriting version
- child2 inheriting version

两个 child 都产生带有工件的 JAR,而 parent 产生空的 JAR,我根本不想在任何地方上传。

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

我试过 gradle-release plugin ,但我很难正确配置它。我得到以下任何一种:
  • 在父级上应用插件,获得正确的提交和标记,但只上传根项目
  • 在子项目上应用插件,正确上传项目,但每个子项目都有单独的提交和标签
  • 最佳答案

    我遇到了同样的问题,最后在 gradle-svn-tools 插件 ( https://github.com/martoe/gradle-svntools-plugin ) 的帮助下在 Gradle 中编写了必要的步骤。请注意,我不是 Groovy 专家,所以我想有几件事可以更轻松地完成 :)

    我在父项目中的 build.gradle:

    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 脚本:
    # 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}

    希望这可以帮助。

    关于gradle - 在 Gradle 中使用一个版本和标签发布多模块项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39470809/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com