How about composite builds? Let’s say there are two builds: buildscript and example, example includes buildscript by the following declaration in its settings.gradle.kts:
pluginManagement {
includeBuild("../buildscript")
}
All attempts to access version catalogs declared in buildscript’s settings.gradle.kts fail for me if done from inside of some org.gradle.api.Plugin located in buildscript. With the code provided above (project.rootProject.extensions.getByType(VersionCatalogsExtension.class)...) it’s only possible to get example’s version catalogs.
Is there any way to access a version catalog declared inside buildscript’s settings.gradle.kts to use it from some buildscript’s Plugin?
Update. I think I’ve got the picture - when we use constructions like project.rootProject.extensions.getByType(VersionCatalogsExtension.class)... inside plugins, the only version catalogs we can access - are those declared in the target project’s (to which we are going to apply the plugin) settings.gradle.kts. In other words, there seems to be no straightforward way to encapsulate version catalogs to be used inside plugins.
One more update. What I want to have is some automatic type-safe codebase generation allowing to add similar version catalogs from .toml files not at the Gradle’s buildscript level, but inside Gradle project’s codebase (which is usually src/main/kotlin/... or anything else linked by the sourceSet configuration). So in the case of composite builds described above, buildscript’s plugins get an access to version catalogs in an encapsulated manner regardless from what these plugins are going to be applied to eventually.
So everything I wrote above can be rephrased as: is there any Gradle plugin generating type-safe wrappers for .toml-based version catalogs and adding generated classes to project’s sources? Something like:
plugins {
id("toml-wrappers-generator")
}
tomlWrappersGenerator {
addTargetTomlCatalog(../dependencies.toml)
}
// Now this project has got DependenciesCatalog.kt included into its compilation sources.