I would like to know how to have a convention plugin that applies some other plugins but I’m having a really hard time finding information about this online.
I have a multi module gradle setup and I have two gradle projects that both apply the kotlin plugin in their build script like this
// app1/build.gradle.kts and app2/build.gradle.kts
plugins {
base
java
idea
id("org.jetbrains.kotlin.jvm") as "1.6.10"
}
// Then some supporting implementation statements with supporting dependencies like kotlin-stdlib-jdk8 and kotlin-reflect
I would like to consolidate this logic into my convention plugin that is defined in buildSrc, however I am struggling to figure out how to do this. If I move the plugin definition into my buildSrc/src/main/kotlin/my-common-conventions.gradle.kts
exactly as-is I get an error message that having the version defined in the convention plugin isn’t allowed. Invalid plugin request [id: 'org.jetbrains.kotlin.jvm', version: '1.6.10']. Plugin requests from precompiled scripts must not include a version number. Please remove the version from the offending request and make sure the module containing the requested plugin 'org.jetbrains.kotlin.jvm' is an implementation dependency of project ':buildSrc'.
So I can remove the version number from the kotlin plugin and the it builds okay.
However, I want to know how I can pin the plugin definition to a specific version, and more than that I would like to know the best practice. I know that regular dependencies defined in the depenendencies
block with implementation
/api
are included in the convention plugin, even when versions are specified. But somehow plugin versions in the convention plugin’s plugin
block are different. How can we use a common configuration across projects that implements a plugin’s version number?