This message was deleted.
# community-support
s
This message was deleted.
c
You’ll see that pattern where a plugin (perhaps defined in buildSrc) applies a 3rd party plugin, requiring the class files to both apply the plugin and likely configure it. Plugin versions are needed where they are applied - if you have multiple locations applying plugins (plugins applying plugins, subprojects applying plugins, etc) may need to look at pulling all those into convention plugins and applying plugins in a uniform way, and from there looking to standardize version management.
v
Yes, you can use a version catalog of the parent build in
buildSrc/build.gradle(.kts)
by importing it in the
buildSrc/settings.gradle(.kts)
.
t
Fwiw, I've been using a helper function to generate the plugin marker coordinates from the plugin ID for a while:
Copy code
dependencies {
    implementation(plugin(id = "com.diffplug.spotless", version = "5.14.1"))
}
// <https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers>
fun plugin(id: String, version: String) = "$id:$id.gradle.plugin:$version"
and am now using version catalogs with a similar function:
Copy code
dependencies {
    implementation(plugin(libs.plugins.spotless))
}
// <https://github.com/gradle/gradle/issues/17963>
// <https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers>
fun plugin(plugin: Provider<PluginDependency>) = plugin.map { "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" }
❤️ 1
thank you 1
j
@Thomas Broyer Looks useful, thanks! Does it work with any plugin? For example the SpotBugs Gradle plugin is using a different pattern: https://plugins.gradle.org/plugin/com.github.spotbugs
Copy code
dependencies {
  classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.6"
}
Copy code
id "com.github.spotbugs" version "5.0.6"
Ah, the marker artifact is always using the same pattern. 💡
t
It works with every single plugin as that's how Gradle does it when you use
plugins { id("com.github.spotbugs") }
(see the link in comment next to the function). The thing is, that plugin marker artifact is only a POM that depends on the actual artifact of the plugin: https://plugins.gradle.org/m2/com/github/spotbugs/com.github.spotbugs.gradle.plugin/5.0.6/com.github.spotbugs.gradle.plugin-5.0.6.pom
👍 1
j
@Thomas Broyer that function only works if the plugin id is following a concrete naming convention no?
t
No. As soon as it's usable with the plugins DSL, this is how Gradle resolves it itself (and if it's not usable with the plugins DSL, you already know exactly which Maven coordinates to use)
👍 1
https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers
Since the
plugins {}
DSL block only allows for declaring plugins by their globally unique plugin
id
and
version
properties, Gradle needs a way to look up the coordinates of the plugin implementation artifact. To do so, Gradle will look for a Plugin Marker Artifact with the coordinates
plugin.id:plugin.id.gradle.plugin:plugin.version
. This marker needs to have a dependency on the actual plugin implementation.
v
It's also independent of the coordinates of the actual code jar. Because one code jar could contain multiple plugins. That's why the plugin marker artifacts are separate.