Build Status Gradle Plugin Portal

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.4.3

Release date: 2024-02-28

Bug fixes

0.4.2

Release date: 2023-06-03

Bug fixes

  • Make plugin compatible with Gradle 8.x (#94)

0.4.1

Release date: 2023-01-20

Bug fixes

  • Make plugin compatible with Java 17 (#89)

0.4.0

Release date: 2022-03-11

Bug fixes

  • Descriptor generation is up to date although mojo dependency changed (#13)

  • @Parameter in abstract classes in other modules are ignored (#73)

Breaking changes

  • The mojo configuration was removed without replacement. The plugin now searches the compile classpath instead.

  • Property mojoDependencies dropped from GenerateMavenPluginDescriptorTask without replacement.

0.3.1

Release date: 2020-09-27

Changes

  • Build cache support (#7)

  • Plugin jar contains LICENSE file (#26)

  • Additional project metadata added to published plugin POMs (#47)

  • More idiomatic task dependency modelling (#35)

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).

Bug fixes

  • Task descriptions for help and descriptor task are swapped (#34)

  • Help mojo task is never up to date because descriptor tasks modifies outputs (#16)

Deprecations

  • The generateHelpMojo setting has been deprecated in favor of helpMojoPackage

Breaking changes

  • Class de.benediktritter.maven.plugin.development.task.HelpGeneratorAccessor has been removed

0.2.1

Release date: 2020-05-02

New Features

  • Tasks provide proper descriptions (#22)

Bug Fixes

  • Build fails when java plugin is not applied explicitly (#19)

  • Typing of parameters API is incorrect (#23)

0.2.0

Release date: 2020-04-16

New Features

  • Add DSL for declaring mojos in the build script (#4)

  • Provide way to configure plugin dependencies (#12)

  • Define dedicated configuration for projects providing mojos (#11)

  • Add support for mojos from other projects (#3)

Bug Fixes

  • Force version upgrade of qdox (#9)

Breaking changes

  • Package de.benediktritter.maven.plugin.development.model has been removed.

0.1.0

Release date: 2020-04-05

Initial release