【问题标题】:Gradle - auto update dependency versionGradle - 自动更新依赖版本
【发布时间】:2017-12-26 03:57:18
【问题描述】:

我有发布应用程序的 Jenkins CI 管道。此过程以人员触发应用程序发布工作的方式工作。此作业通过 gradle dependencies 命令检查所有项目依赖项。对于所有属于快照发布作业的依赖项,都会自动触发。 发布作业只需升级 lib/应用程序版本并将其部署在工件中。

如何在 gradle 中自动将 SNAPSHOT 依赖版本升级为发布版本?

我的 build.gradle 文件如下所示:

Properties versions = new Properties()
versions.load(new FileInputStream(rootProject.projectDir.path + "/version.properties"))

dependencies {
    compile("projectA:${versions.projectAVersion}")
    compile("projectB:${versions.projectBVersion}")
}

和version.properties文件

projectAVersion=1.1.0-SNAPSHOT
projectBVersion=1.1.0-SNAPSHOT

事实上,我正在寻找类似于 maven 版本插件的东西。

  • 是否可以在 build.gradle 中自动升级版本号?怎么样?
  • 更难的版本 - 当版本在外部 version.properties 文件中时,是否可以升级版本号?

编辑

事实上,我只需要 Gradle 中的 Maven 版本插件(版本:use-releases 和版本:use-next-releases)功能。

【问题讨论】:

  • “自动升级版本号”是什么意思?只需去掉-SNAPSHOT,或者查找最新发布的版本并使用它,或者...?
  • 您想在version.properties 更改时以某种方式触发构建?
  • @lbednaszynski,你的意思是像这个 maven 插件(mojohaus.org/versions-maven-plugin/usage.html),对吧?我在 Gradle 中有同样的要求,但我找不到任何插件来自动更新版本,就像你提到的那样。我发现的唯一插件仅提供最新插件的报告 (github.com/ben-manes/gradle-versions-plugin)。

标签: gradle build.gradle


【解决方案1】:

我对你的问题不是很清楚。我的理解是,您需要在每次构建后动态更新版本值。

您可以做的是,获取属性值。删除 -SNAPSHOT。每次构建后以增量更新 1.1.0。如 1.1.1、1.1.2 等。

这可以通过

      task testing { 
        Properties props = new Properties()
      //getting and loading the property file
      //Give proper path to file
        File propsFile = new File('version.properties')
        props.load(propsFile.newDataInputStream())
       //Now strip of -SNAPSHOT and get the last digit and increment it by 1
            Integer rand = props.getProperty('lastDigit').toInteger()+1
            String variable=rand.toString()
        //Append -SNAPSHOT with 'variable and set the property  
            props.setProperty('version',variable)
            props.store(propsFile.newWriter(), null)
      }

如果我对您的问题的理解是正确的,这将起作用。

【讨论】:

    猜你喜欢
    • 2015-10-18
    • 1970-01-01
    • 2019-06-15
    • 2017-08-21
    • 2015-04-16
    • 2014-09-17
    • 2018-06-02
    • 1970-01-01
    • 2023-04-08
    相关资源
    最近更新 更多