gpt4 book ai didi

gradle - Gradle-自动更新依赖版本

转载 作者:行者123 更新时间:2023-12-03 05:55:20 25 4
gpt4 key购买 nike

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

如何自动将SNAPSHOT依赖版本升级到Gradle中的发布版本?

我的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。每次构建后以增量方式更新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)
    }

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

    关于gradle - Gradle-自动更新依赖版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45214947/

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