I am trying two things with a Gradle plugin that worked on Gradle 8, but does not work on Gradle 9:
- Get a version from the version catalogs
- Add a dependency to a project (with the version from the catalog)
So far, I don’t know how to get the version catalogs extension without using afterEvaluate. But in Gradle 9, if I use afterEvaluate, I can’t add dependencies because they are immutable after resolution. If I remove afterEvaluate, the extension is not present.
private fun Project.configureDependencies() {
afterEvaluate {
val catalog = extensions.getByType(VersionCatalogsExtension::class.java).named("libs")
dependencies.add(
"implementation",
"some:" + catalog.findVersion("versionName").orElseThrow {
IllegalArgumentException("Version with alias $versionAlias not found in version catalog")
},
)
}
}
What can I do to achieve 1 & 2