To be able to use Kotlin DSL accessors in your Gradle build scripts you have to use the new plugins DSL, even though its still in incubating state. That means, the process of publishing the plugin is slightly different from an "old way" of creating Gradle plugins.
Because I host my plugin's source code on GitHub and I am using JitPack to publish the plugin, there are some limitations to what the plugin should look like.
- Plugin cannot use Kotlin based build scripts, since JitPack does not recognize it.
- Plugin has to stick with Gradle 3.x API, because JitPack does not work with 4.x version yet.
Plugin build scripts
Specify the project/plugin name in the settings.gradle
file. In my case, it is:
rootProject.name = "Quantum-Leap-Gradle-Plugin"
In the build.gradle
script, use the java-gradle-plugin
which generates necessary plugin-metadata for you, and maven-publish
plugin which is recognized by JitPack and allows it to deploy the plugin into a Maven repository.
Then configure the plugin's metadata. Specify the plugin's id as a <group>.<project name>
so Gradle will find a correct plugin on a correct path when looking for it in a Maven repository.
plugins {
id 'java-gradle-plugin'
id 'maven-publish'
}
group = "com.github.vkuzel"
version = "2.0.3-2"
// Other stuff like repositories, dependencies, etc.
gradlePlugin {
plugins {
create("QuantumLeapPlugin") {
id = "com.github.vkuzel.Quantum-Leap-Gradle-Plugin"
implementationClass = "cz.quantumleap.gradle.QuantumLeapPlugin"
}
}
}
Using the plugin
Because the JitPack is not a "standard" Maven repository, you have tell plugins DSL about it. To do this, add following block to your project's settings.gradle.kt
file.
pluginManagement {
repositories {
mavenCentral()
maven(url = "https://jitpack.io")
}
}
Apllication of the plugin in build.gradle.kts
script is then straightforward.
plugins {
id("com.github.vkuzel.Quantum-Leap-Gradle-Plugin") version "2.0.3-3"
}