jmfayard
02/12/2022, 4:02 PMgradle/libs.versions.toml
for my plugin refreshVersions
But I noticed that there is version catalog API available in build.gradle.kts
// build.gradle.kts
val versionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
println("Library aliases: ${versionCatalog.libraryAliases}")
Exactly what I need!
But if I put the same code in my plugin:
open class RefreshVersionsMigrateTask : DefaultTask() {
@TaskAction
fun versionsCatalog() {
val versionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
println("Library aliases: ${versionCatalog.dependencyAliases}")
}
}
Then I get:
Execution failed for task ':refreshVersionsMigrate'.
Extension of type 'VersionCatalogsExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension]Is there a way to make it work or should I parse the file
libs.versions.toml
manually?Vampire
02/12/2022, 4:07 PMlibraryAliases
vs. dependencyAliases
), you just call it on the wrong object.Vampire
02/12/2022, 4:08 PMextensions
of the Task
which also is ExtensionAware
but does not have the extension you are after and if you query extensions
explicitly there is no delegation strategy.Vampire
02/12/2022, 4:08 PMproject.extensions
and it should work just fine.Vampire
02/12/2022, 4:09 PMExtensionAware
instance to the error message, I also fell into that trap a few times already.melix
02/12/2022, 4:09 PMmelix
02/12/2022, 4:10 PMjmfayard
02/12/2022, 5:04 PMjmfayard
02/12/2022, 5:08 PMI don't think using the API you mention is going to help you because it represents a realized catalog.That's fine, I'm not modifying the file
libs.versions.toml
,
I'm using its content to rewrite the files build.gradle(.kts)
https://github.com/jmfayard/gradle-versions-catalog/commit/c9f9dfe12861ea409c06416fc2d25f150067e9fbmelix
02/12/2022, 8:38 PMjmfayard
02/12/2022, 8:56 PMlibs.versions.toml
and updating the build.gradle(.kts)
is half of the work of integrating refreshVersions and the versions catalog.
The second half will be that refreshVersions add the available versions updates as comments in the libs.versions.toml
directly, if the versions are present there.