what's the syntax for applying a plugin using vers...
# gradle
f
what's the syntax for applying a plugin using version catalogs and build convention? Details in thread.
not kotlin but kotlin colored 1
I have this in the
toml
file
Copy code
[plugins]
com-android-compose-screenshot = { id = "com.android.compose.screenshot", version.ref = "com-android-compose-screenshot-version"}
and I'm trying to apply the plugin like so
Copy code
class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            pluginManager.apply("com.android.library")
            pluginManager.apply("kotlin-parcelize")
            
            // plugin applied here
            val plugin = catalog.findPlugin("com.android.compose.screenshot").get().get()
            pluginManager.apply(plugin.pluginId)
            val extension = extensions.getByType<LibraryExtension>()
            configureAndroidCompose(extension)
        }
    }
}
the plugin is not resolved,
Copy code
* What went wrong:
An exception occurred applying plugin request [id: 'weathersample.android.library.compose']
> Failed to apply plugin 'weathersample.android.library.compose'.
   > Plugin with id 'com.android.compose.screenshot' not found.
e
that should work if
[plugins] com-android-compose-screenshot
is in the consumer project
f
I'll check tomorrow, thanks
v
If you would want to control the version in the plugin project, add a dependency on that other plugin in your plugins's build script
f
I think I'm missing a dependency in the plugin's
build.gradle
file, I have these in there
Copy code
dependencies {
    compileOnly(libs.com.android.tools.build.gradle)
    compileOnly(libs.org.jetbrains.kotlin.kotlin.gradle.plugin)
    compileOnly(libs.io.gitlab.arturbosch.detekt)
}
so I may need to add a dependency for the screenshot plugin as well?
that didn't help, I've added
Copy code
com-android-compose-screenshot-plugin = { module = "com.android.compose.screenshot:com.android.compose.screenshot.gradle.plugin", version.ref = "com-android-compose-screenshot-version" }
in the
toml
file and
Copy code
dependencies {
    compileOnly(libs.com.android.tools.build.gradle)
    compileOnly(libs.org.jetbrains.kotlin.kotlin.gradle.plugin)
    compileOnly(libs.io.gitlab.arturbosch.detekt)
    compileOnly(libs.com.android.compose.screenshot.plugin)
}
in the build.gradle but still no dice
e
to the plugin's toml or to the applying project's?
f
there is only one
toml
file
not sure I understand the question
v
If you only add that plugin to
compileOnly
in your plugin build, that does not change anything. You do not use any classes, but only apply by id, so
compileOnly
of course does not make any difference.
And whether you have the plugin in the version catalog of the consumer build or not also does not make any difference
A version catalog is just a catalog of things to pick from. Having something there alone does not have any effect.
That in your plugin you get the version catalog entry for that plugin and get the plugin id from that entry is technically identical to just hard-code the ID String.
The only difference is, that the catalog could define a different ID
f
well, the idea is to have the versioning in the toml
v
But that does not bring the plugin onto the classpath so you cannot apply it
f
ok, do you have any pointer on how to go about it?
v
Sure, read my first response for example
Sounds like you are anyway talking about convention plugins within one build and not a plugin that is used in multiple builds
So just add an
implementation
dependency on the plugin to your plugin build and you are fine
f
I did, but that didn't shed much light unfortunately, it probably assumes some knowledge on my part I don't have
v
You did not
At least not in what you showed
f
I was replying to your "read my first comment" message
v
Ah, sorry, got you wrong
But well, I just explained it again in different words
f
so change
compileOnly
to
implementation
?
👍 1
v
And if you do not understand something that someone trying to help you says, it could help to ask for clarification instead of just discarding. ;-)
f
well, the message came while I was sound asleep
v
Dare you ever sleeping!
f
that seems to have worked, thanks!
👌 1
v
😄