This project serves as a template for Gradle binary plugin, it contains minimal content to compile. It also contains source code for following lectures:
- Gradle Plugin Development - Binary Plugin
- Gradle Plugin Development - Publishing - Local Maven Repository
- Gradle Plugin Development - Publishing - Private Maven Repository
To successfully create a plugin you should:
- Import
java-gradle-plugin
core Gradle plugin - Create class implementing
Plugin
interface and extendingapply()
method - Define plugin descriptor in
build.gradle
script file
First of, this is a standalone project with the JVM structure.
Inside of src/main/java
directory there is GreetingPlugin class implementing Plugin interface.
In order to be able to refer to Gradle API components like Plugin interface you should apply plugin java-gradle-plugin
inside build.gradle
file.
Plugin will print simple logging statement at the configuration time of the project, to proof that the plugin is applied.
In order that plugin descriptor will be generated you have to specify plugins inside the
gradlePlugin{}
block.
To be able to publish plugin to a Maven repository you have to apply maven-publish
plugin, which will give you ability
of artifact publication.
To publish compiled plugin to Local Maven repository you have to run task publishToMavenLocal
. As a result this plugin will
be published to {user-home}/.m2/repository/com/rivancic/greeting-plugin
directory.
To be able to reference this plugin from withing a project you will have to define Local Maven repository inside of
pluginManagement{}
block in settings.gradle
file.
In case you will need to deploy a plugin to private or remote Maven repository you will have to specify its information in
publishing{ repositories{}}
block. Among others, you can specify inside MavenArtifactRepository following properties: URL, name, option to deploy to repository over unsecure connection, credentials, ...
Example of the block:
publishing {
repositories {
maven {
url = "http://localhost:8080/repository/internal"
name = "mavenArchivaPrivate"
allowInsecureProtocol = true
credentials {
username = "$privateArchivaUser"
password = "$privateArchivaPassword"
}
}
}
}
Once you want to reference the Gradle plugin that is deployed on a remote repository you will have to specify the repository in
settings.gradle
file in pluginManagement{}
block with the same maven repository definition.