Support for changing Gradle dependency versions in TOML files
What problem are you trying to solve?
We specify all of our dependencies and their versions inside toml files for our gradle projects. We would like a away to automate the upgrading of these versions via open rewrite.
Describe the solution you'd like
Recipe available for changing the version of a dependency specified in a toml file
Have you considered any alternatives or workarounds?
Consider using the find and replace recipe but it leads to several work arounds having to be in place for it to work.
Additional context
https://rewriteoss.slack.com/archives/C01A843MWG5/p1723123348552829
Thanks for logging it as an issue! As indicated we do have a toml parser, but that'd need to be dusted off and cleaned up a bit before putting that to use. Likely to tie in with the recently added
- https://github.com/openrewrite/rewrite/pull/4394
@steplica thanks a lot for the offer to help!
- I think in the early stages of getting the parser to work @KnutWannheden might be best to guide you, as he's been most active with recent parser developments. I'd expect
rewrite-tomlshould still be part ofopenrewrite/rewrite, with an eye towards integration with Gradle - once the parser works we'd need to hook it into the rewrite-maven-plugin and rewrite-gradle-plugin, and rewrite-polyglot
- then once files are parsed as Toml, we'd need to integrate with our Gradle support; at that point we can tag Shannon Pamperl (also here) for guidance, likely looking towards our Trait support to minimize recipe changes
will this also support gradle version catalogs defined in settings.gradle (no toml files involved) ?
👍 sounds good. I will keep an eye on this issue.
- One step closer after https://github.com/openrewrite/rewrite/pull/4845
Next steps:
- [ ] Update
gradle.UpgradeDependencyVersionto handle dependencies from the Gradle Version Cataloglibrariestable with the version appearing in a String literal [1] - [ ] Update
gradle.UpgradeDependencyVersionto handle dependencies from the Gradle Version Cataloglibrariestable with the version appearing within the defined inline table [2] - [ ] Update
gradle.UpgradeDependencyVersionto handle dependencies from the Gradle Version Cataloglibrariestable with a version reference being used [3] - [ ] Update
gradle.plugins.UpgradePluginVersionto handle plugins from the Gradle Version Catalogpluginstable with the version appearing in a String literal [4] - [ ] Update
gradle.plugins.UpgradePluginVersionto handle plugins from the Gradle Version Catalogpluginstable with the version appearing within the defined inline table [5] - [ ] Update
gradle.plugins.UpgradePluginVersionto handle plugins from the Gradle Version Catalogpluginstable with a version reference being used [6]
[1] build.gradle
dependencies {
implementation(libs.guava)
}
gradle/libs.versions.toml
[libraries]
guava = "com.google.guava:guava:29.0-jre"
[2] build.gradle
dependencies {
implementation(libs.guava)
}
gradle/libs.versions.toml
[libraries]
guava = { group = "com.google.guava", name = "guava", version = "29.0-jre" }
[3] build.gradle
dependencies {
implementation(libs.guava)
}
gradle/libs.versions.toml
[versions]
guava = "29.0-jre"
[libraries]
guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
[4] build.gradle
plugins {
alias(libs.plugins.openrewrite)
}
gradle/libs.versions.toml
[plugins]
openrewrite = "org.openrewrite.rewrite:5.40.0"
[5] build.gradle
plugins {
alias(libs.plugins.openrewrite)
}
gradle/libs.versions.toml
[plugins]
openrewrite = { id = "org.openrewrite.rewrite", version = "5.40.0" }
[6] build.gradle
plugins {
alias(libs.plugins.openrewrite)
}
gradle/libs.versions.toml
[versions]
openrewrite = "5.40.0"
[plugins]
openrewrite = { id = "org.openrewrite.rewrite", version.ref = "openrewrite" }
Additional notes:
With both of these recipes, versions found in .properties files are updated utilizing a separate visitor. The same should be expected for the .toml file as well. In this case, however, the .toml file has a lot more information to go off of given the GAV or plugin ID are directly available within the file itself meaning that the SCAN phase should not be strictly necessary like it is with the .properties variant.
Links:
- https://docs.gradle.org/current/userguide/version_catalogs.html
@tompson, I went ahead and broke out your request to a separate issue as it'll be a little bit different than updating the TOML files themselves.
- https://github.com/openrewrite/rewrite/issues/4852