Gradle Tooling API可以更新依赖项并编写更新后的build.gradle文件。

huangapple go评论84阅读模式
英文:

Can Gradle Tooling API update dependencies and then write an updated build.gradle file?

问题

我看过一些示例代码,使用Gradle Tooling API来解析build.gradle文件,然后在内存中更新依赖项。Tooling API能将这个输出到更新后的build.gradle文件吗?

我尝试使用一个Java库来更新gradle依赖项,而不是尝试在一个Groovy脚本中构建一个复杂的正则表达式来更新依赖项(可以是字符串或映射表示)。如果Tooling API不支持写入更新后的build.gradle文件,我将继续使用Groovy脚本。

这是一个发布过程,我正在发布一个内部模块,然后想要更新其他将发布模块作为依赖项的内部模块的build.gradle文件中的版本。

英文:

I've seen some example code for using the Gradle Tooling API to parse a build.gradle and then update the dependencies in memory. Can the Tooling API output this to an updated build.gradle file?

I'm trying to update gradle dependencies using a java library, rather than trying to build a complicated regex to update dependencies (which could be either string or map notation) in a groovy script. If the Tooling API does not support writing the update build.gradle file, I'll soldier on with groovy script.

This is for a release process, where I'm releasing an internal module and would then like to update the version in the build.gradle file for other internal modules that have the released module as a dependency.

答案1

得分: 1

如果您希望能够更好地更新您的依赖项,我建议使用 toml-version 目录。由于toml是一种明确定义的基于文本的格式,您应该能够使用标准库解析它并写回。

或者,如果您在Github上,您可以尝试使用dependabot或renovate,因为它们支持在Gradle中自动化依赖项更新。

英文:

If you want to be able to better update your dependencies, I'd recommend to use toml-version catalogues. Since toml is a well defined text based format, you should be able to parse it with standard libraries and write it back.

Alternatively, if you are on Github you could try using either dependabot or renovate, as they have support for automating dependency updates in Gradle.

答案2

得分: 0

我已经使用Tooling API做了同样的事情,原因也一样,除了不需要更新build.gradle文件。您可以将依赖版本放在gradle.properties中,并通过运行一个“独立”的程序来更新它,该程序使用Tooling API。您甚至可以进一步创建Git标签或分支。

英文:

I have done the same thing with the Tooling API for the same reason, except, there’s no need to update the build.gradle file. You can put the dependency versions in gradle.properties, and update it by running a separate program that uses the Tooling API. You can even go as far as creating Git tags or branches.

huangapple
  • 本文由 发表于 2023年6月30日 01:08:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76583214.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定