is there a way to have a settings plugin add a plu...
# plugin-development
j
is there a way to have a settings plugin add a plugin to the classpath so that the plugin can be applied via id (no version) in the root build.gradle? right now I am adding the dependencies via
gradle.rootProject.buildscript.dependencies
but that only works for applying the plugins in subprojects for some reason. in the root build.gradle, i still get
org.gradle.api.plugins.UnknownPluginException: Plugin [id: '...'] was not found in any of the following sources:
in my project that uses the settings plugin, if i put
Copy code
buildscript {
    dependencies {
        classpath("myplugin")
    }
}
in settings.gradle.kts, it works
but i can't seem to replicate that in the settings plugin
v
Just depend on that other plugin, that's it.
j
yeah, i was hoping to choose the version based on logic within the settings project though, but this will be my fallback plan
i was surprised gradle.rootProject didnt work for the.... root project
v
The buildscript dependencies in the settings script works, as it is like depending on it, you add it to the classloader for the settings script which is a parent class loader of the build script
But if you add it to the buildscript classpath of the build script manually it will also not be found for usage in the plugins block by id
The plugins block is extracted and evaluated separately in a dummy project to find out which type-safe accessors to generate.
And there the addition of the buildscript classpath of the build script would not be available either
j
Yeah. I was previously using a custom wrapper to declare pluginManagement so that plugins can be declared in projects by id with no version. But since pluginManagement doesn't actually add it to the class path (the actual plugins{} usage is what triggers this.) Then we would still have issues where plugins applied only at subproject level would get the wrong versions of dependencies (if that transitive dep was already resolved at root level). So my new idea is to use a settings plugin to manage the root buildscript directly. But for some reason plugins added this way via rootProject.buildscript are not available to apply via ID in the root project, only subprojects
I.know i could do that with the wrapper too, but i have some other reasons why I want the extra layer of wrapper -> settings plugin -> project plugins too