Maven Plugin Builder Gradle Plugin

The Maven Plugin Builder Gradle Plugin lets you generate the Maven plugin descriptor for any Mojos found in your project.

The plugin has been successfully tested with Gradle 4.10.2.

Usage

To use the plugin, include it in your build script:

buildscript {
    dependencies {
        classpath group: "com.liferay", name: "com.liferay.gradle.plugins.maven.plugin.builder", version: "1.2.4"
    }

    repositories {
        maven {
            url "https://repository-cdn.liferay.com/nexus/content/groups/public"
        }
    }
}

apply plugin: "com.liferay.maven.plugin.builder"

Tasks

The plugin adds two tasks to your project:

NameDepends OnTypeDescription
buildPluginDescriptorcompileJava, WriteMavenSettingsBuildPluginDescriptorTaskGenerates the Maven plugin descriptor for the project.
WriteMavenSettings-WriteMavenSettingsTaskWrites a temporary Maven settings file to be used during subsequent Maven invocations.

The Maven Plugin Builder Plugin automatically applies the java plugin.

The plugin also adds the following dependencies to tasks defined by the maven plugin:

NameDepends On
install, uploadArchives, and all the other tasks of type UploadbuildPluginDescriptor

The buildPluginDescriptor task is automatically configured with sensible defaults:

Property NameDefault Value
classesDirsourceSets.main.output.classesDir
mavenEmbedderClasspathconfigurations.mavenEmbedder
mavenSettingsFilewriteMavenSettings.outputFile
outputDirThe directory META-INF/maven in the first resources directory of the main source set (by default: src/main/resources/META-INF/maven).
pomArtifactIdThe bundle symbolic name of the project inferred via the OsgiHelper class.
pomGroupIdproject.group
pomVersionproject.version (if it ends with "-SNAPSHOT", the suffix will be removed)
sourceDirThe first java directory of the main source set (by default: src/main/java).

The plugin ensures that the processResources task always runs before buildPluginDescriptor to let processResources copy the newly generated files in the buildPluginDescriptor.outputDir directory.

The writeMavenSettings task is also automatically configured with sensible defaults:

Property NameDefault Value
localRepositoryDirmaven.repo.local system property
nonProxyHostshttp.nonProxyHosts system property
outputFile"${project.buildDir}/settings.xml"
proxyHosthttp.ProxyHost or https.proxyHost system property (depending on the protocol of repositoryUrl)
proxyPasswordhttp.ProxyPassword or https.proxyPassword system property (depending on the protocol of repositoryUrl)
proxyPorthttp.ProxyPort or https.proxyPort system property (depending on the protocol of repositoryUrl)
proxyUserhttp.ProxyUser or https.proxyUser system property (depending on the protocol of repositoryUrl)
repositoryUrlrepository.url system property

If running on JDK8+, the plugin also disables the doclint feature in all tasks of type Javadoc.

BuildPluginDescriptorTask

Tasks of type BuildPluginDescriptorTask work by generating a temporary pom.xml file based on the project, and then invoking the Maven Embedder to build the Maven plugin descriptor.

It is possible to declare information for the plugin descriptor generation using either Java 5 Annotations or Javadoc Tags.

Task Properties

Property NameTypeDefault ValueDescription
classesDirFilenullThe directory that contains the compiled classes. It sets the value of the build.outputDirectory element in the generated pom.xml file.
configurationScopeMappingsMap<String, String>["compile": "compile", "provided", "provided"]The mapping between the configuration names in the Gradle project and the dependency scopes in the pom.xml file. It is used to add dependencies.dependency elements in the generated pom.xml file.
forcedExclusionsSet<String>[]The group:name:version notation of the dependencies to always exclude from the ones added in the pom.xml file. It adds dependencies.dependency.exclusions.exclusion elements to the generated pom.xml file.
goalPrefixStringnullThe goal prefix for the Maven plugin specified in the descriptor. It sets the value of the build.plugins.plugin.configuration.goalPrefix element in the generated pom.xml file.
mavenDebugbooleanfalseWhether to invoke the Maven Embedder in debug mode.
mavenEmbedderClasspathFileCollectionnullThe classpath used to invoke the Maven Embedder.
mavenEmbedderMainClassNameString"org.apache.maven.cli.MavenCli"The Maven Embedder’s main class name.
mavenPluginPluginVersionString"3.4"The version of the Maven Plugin Plugin to use to generate the plugin descriptor for the project.
mavenSettingsFileFilenullThe custom settings.xml file to use. It sets the --settings argument on the Maven Embedder invocation.
outputDirFilenullThe directory where the Maven plugin descriptor files are saved.
pomArtifactIdStringnullThe identifier for the artifact that is unique within the group. It sets the value of the project.artifactId element in the generated pom.xml file.
pomGroupIdStringnullThe universally unique identifier for the project. It sets the value of the project.groupId element in the generated pom.xml file.
pomRepositoriesMap<String, Object>["liferay-public": "http://repository.liferay.com/nexus/content/groups/public"]The name and URL of the remote repositories. It adds repositories.repository elements in the generated pom.xml file.
pomVersionStringnullThe version of the artifact produced by this project. It sets the value of the project.version element in the generated pom.xml file.
sourceDirStringnullThe directory that contains the source files. It sets the value of the build.sourceDirectory element in the generated pom.xml file.
useSetterCommentsbooleantrueWhether to allow Mojo Javadoc Tags in the setter methods of the Mojo.

The properties of type File support any type that can be resolved by project.file. Moreover, it is possible to use Closures and Callables as values for the String properties, to defer evaluation until task execution.

Task Methods

MethodDescription
void configurationScopeMapping(String configurationName, String scope)Adds a mapping between a configuration name in the Gradle project and the dependency scope in the pom.xml file.
BuildPluginDescriptorTask forcedExclusions(Iterable<String> forcedExclusions)Adds group:name:version notations of dependencies to always exclude from the ones added in the pom.xml file.
BuildPluginDescriptorTask forcedExclusions(String... forcedExclusions)Adds group:name:version notations of dependencies to always exclude from the ones added in the pom.xml file.
BuildPluginDescriptorTask pomRepositories(Map<String, ?> pomRepositoriesAdds names and URLs of remote repositories in the pom.xml file.
BuildPluginDescriptorTask pomRepository(String id, Object url)Adds the name and URL of a remote repository in the pom.xml file.

WriteMavenSettingsTask

Task Properties

Property NameTypeDefault ValueDescription
localRepositoryDirStringnullThe directory of the system’s local repository. It sets the value of the localRepository element in the generated settings.xml file.
nonProxyHostsStringnullThe patterns of the host that should be accessed without going through the proxy. It sets the value of the proxies.proxy.nonProxyHosts element in the generated settings.xml file.
outputFileFilenullThe generated settings.xml file.
proxyHostStringnullThe host name or address of the proxy server. It sets the value of the proxies.proxy.host element in the generated settings.xml file.
proxyPasswordStringnullThe password to use to access a protected proxy server. It sets the value of the proxies.proxy.password element in the generated settings.xml file.
proxyPortStringnullThe port number of the proxy server. It sets the value of the proxies.proxy.port element in the generated settings.xml file.
proxyUserStringnullThe user name to use to access a protected proxy server. It sets the value of the proxies.proxy.username element in the generated settings.xml file.
repositoryUrlStringnullThe URL of the repository mirror. It sets the value of the mirrors.mirror.url element in the generated settings.xml file.

The properties of type File support any type that can be resolved by project.file. Moreover, it is possible to use Closures and Callables as values for the String properties, to defer evaluation until task execution.

Additional Configuration

There are additional configurations that can help you use the Maven Plugin Builder.

Maven Embedder Dependency

By default, the plugin creates a configuration called mavenEmbedder and adds a dependency to the 3.3.9 version of the Maven Embedder. It is possible to override this setting and use a specific version of the tool by manually adding a dependency to the mavenEmbedder configuration:

dependencies {
    mavenEmbedder group: "org.apache.maven", name: "maven-embedder", version: "3.3.9"
    mavenEmbedder group: "org.apache.maven.wagon", name: "wagon-http", version: "2.10"
    mavenEmbedder group: "org.eclipse.aether", name: "aether-connector-basic", version: "1.0.2.v20150114"
    mavenEmbedder group: "org.eclipse.aether", name: "aether-transport-wagon", version: "1.0.2.v20150114"
    mavenEmbedder group: "org.slf4j", name: "slf4j-simple", version: "1.7.5"
}

System Properties

It is possible to set the default value of the mavenDebug property for a BuildPluginDescriptorTask task via system property:

  • -D${task.name}.maven.debug=true

For example, run the following Bash command to invoke the Maven Embedder in debug mode to attach a remote debugger:

./gradlew buildPluginDescriptor -DbuildPluginDescriptor.maven.debug=true
« Lang Builder Gradle PluginNode Gradle Plugin »
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています