Publishing Gradle Plugin
We have built different types of libraries with Gradle. This time we are going to build Gradle Plugin with Jarbird.
The sample project is here
From the perspective of the build script with Jarbird, building Gradle Plugin is the same as building conventional JAR libraries. All additional things are in the pom.yaml
Please refer to the gradleplugin
project in the jarbirdsamples
GitHub repo.
Note that if we publish Gradle Plugin in the old way, that no plugin ID is defined, we don't need any special means to publish it. It is just a conventional JAR library. In this section, we focus on publishing a new style Gradle Plugin that has a plugin ID.
#
Gradle Portal accountAn account is needed to publish to Gradle Plugin Portal.
#
pom.yamlBeside the usual information, we added one more section for Gradle plugin:
group: jarbirdsamplesartifactId: gradlepluginversion: 1.0packaging: jar# ...the rest of pom.ymlplugin: id: jarbirdsamples.plugin displayName: Demo of simple Gradle Plugin implementationClass: simplelib.SimplePlugin tags: - publish
From the perspective of the remote repository, a Gradle plugin consists of two parts.
One is the JAR library that contains the Gradle plugin code(jarbirdsamples:gradleplugin:1.0
in this example). It is published just like any other JAR libraries. The other part is the so-called "Plugin Marker Publication", which relate the plugin ID used in the new style plugins
block in the build script, to the JAR library of the plugin itself.
Define the plugin ID as above (jarbirdsamples.plugin
), and the implementation class of the plugin (simplelib.SimplePlugin
). Then we can build the plugin as usual with ./gradlew jbPublishToMavenLocal
.
#
build.gradleTo make it easier to use Gradle Plugin, we usually publish it to Gradle Plugin Portal. It is essentially a Maven repository that Gradle uses first to find a plugin. So we don't need to configure the repository in pluginManagement
of settings.gradle
to make the plugin accessible.
- build.gradle
- build.gradle.kts
// ...jarbird { pub { gradlePortal() }}// ...
// ...jarbird { pub { gradlePortal() }}// ...
So we can publish the Gradle Plugin to Maven Local or Gradle Portal by jbPublishToMavenLocal
or jbPublishToGradlePortal
respectively.
We can also publish Gradle Plugin to Maven Central by specifying mavenCentral()
in the pub
block.
If it is published to Maven Local repository, we may inspect the result. Two components are published, and they are at:
~/.m2/repository/jarbirdsamples/gradleplugin/1.0
~/.m2/repository/jarbirdsamples/plugin/jarbirdsamples.plugin.gradle. plugin/1.0
The latter is a so-called plugin marker publication that is used by Gradle to identify plugin by plugin ID. jarbirdsamples.plugin
is the plugin ID.