This plugin aims to fill the tiny gap for people who need to create an Apache Maven plugin from a Gradle build. To do this the plugin wraps around the Maven Plugin Tools API and feeds it with the right inputs from the Gradle build.
Compatible with Gradle 5.5.1 or later.
Features
-
Automatic generation of a maven plugin descriptor containing all mojos in the selected source set (by default the plugin looks for mojo implementations in the main source set)
-
Support for annotation and JavaDoc tag based mojo implementations
-
Optional generation of a help mojo implementation
Usage
Once applied, the plugin adds a MavenPluginDevelopmentExtension
with name mavenPlugin
to the project.
All meta data for the plugin, e.g. groupId
, artifactId
, description
is extracted from the corresponding project properties.
plugins {
id 'de.benediktritter.maven-plugin-development' version '0.4.3'
}
plugins {
id("de.benediktritter.maven-plugin-development") version "0.4.3"
}
HelpMojo generation
It’s possible to generate a help mojo that help users to discover the functionality of your Maven plugin. By default generation of a help mojo is disabled. To enable it specify the package the HelpMojo should be generated in:
mavenPlugin {
helpMojoPackage = 'org.example.help'
}
mavenPlugin {
helpMojoPackage.set("org.example.help")
}
Extracting mojos from other subprojects
The plugin searches the compile classpath for mojo implementations and extracts plugin descriptors from all project dependencies. This means that mojos are not scanned in binary dependencies, only in dependencies that are build from modules of the build that applies this plugin.
dependencies {
implementation project(":mojo-subproject")
}
dependencies {
implementation(project(":mojo-subproject"))
}
Controlling plugin dependencies
By default, all dependencies from the runtime classpath will be added to the dependencies block of the generated plugin descriptor.
This can be changed by configuring the dependencies
property on the mavenPlugin
extension.
In the following examples only org.apache.commons:commons-lang3:3.9
will be added as a dependency to the plugin descriptor:
configurations {
deps
}
dependencies {
deps "org.apache.commons:commons-lang3:3.9"
implementation "com.google.guava:guava:28.0-jre"
}
mavenPlugin {
dependencies = configurations.deps
}
val deps by configurations.creating
dependencies {
deps("org.apache.commons:commons-lang3:3.9")
implementation("com.google.guava:guava:28.0-jre")
}
mavenPlugin {
dependencies.set(deps)
}
Defining mojos in the build script
If you can’t or don’t want to use auto detection of mojos there is also a DSL for defining mojos inside the build script:
mavenPlugin {
mojos {
touch {
implementation = "com.example.MyMojo"
description = "A super fancy mojo defined in my build.gradle"
parameters {
parameter("outputDir", File) {
defaultValue = "\${project.build.outputDirectory}/myMojoOutput"
required = false
}
}
}
}
}
mavenPlugin {
mojos {
create("touch") {
implementation = "com.example.MyMojo"
description = "A super fancy mojo defined in my build.gradle"
parameters {
parameter("outputDir", "java.io.File") {
defaultValue = "\${project.build.outputDirectory}/myMojoOutput"
isRequired = false
}
}
}
}
}
Appendix A: Release History
0.3.0
Release date: 2020-08-02
Note: This release includes a change in behavior of the HelpMojo generation.
Before 0.3.0 generation of a HelpMojo could be turned on by setting generateHelpMojo
to true
.
Starting with 0.3.0 generateHelpMojo
is deprecated and replaced by helpMojoPackage
.
Users now need to define the package of the HelpMojo.
This fixes problems with up-to-date checking (see #16).