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:
Name | Depends On | Type | Description |
---|---|---|---|
buildPluginDescriptor | compileJava , WriteMavenSettings | BuildPluginDescriptorTask | Generates the Maven plugin descriptor for the project. |
WriteMavenSettings | - | WriteMavenSettingsTask | Writes 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:
Name | Depends On |
---|---|
install , uploadArchives , and all the other tasks of type Upload | buildPluginDescriptor |
The buildPluginDescriptor
task is automatically configured with sensible
defaults:
Property Name | Default Value |
---|---|
classesDir | sourceSets.main.output.classesDir |
mavenEmbedderClasspath | configurations.mavenEmbedder |
mavenSettingsFile | writeMavenSettings.outputFile |
outputDir | The directory META-INF/maven in the first resources directory of the main source set (by default: src/main/resources/META-INF/maven ). |
pomArtifactId | The bundle symbolic name of the project inferred via the OsgiHelper class. |
pomGroupId | project.group |
pomVersion | project.version (if it ends with "-SNAPSHOT" , the suffix will be removed) |
sourceDir | The 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 Name | Default Value |
---|---|
localRepositoryDir | maven.repo.local system property |
nonProxyHosts | http.nonProxyHosts system property |
outputFile | "${project.buildDir}/settings.xml" |
proxyHost | http.ProxyHost or https.proxyHost system property (depending on the protocol of repositoryUrl ) |
proxyPassword | http.ProxyPassword or https.proxyPassword system property (depending on the protocol of repositoryUrl ) |
proxyPort | http.ProxyPort or https.proxyPort system property (depending on the protocol of repositoryUrl ) |
proxyUser | http.ProxyUser or https.proxyUser system property (depending on the protocol of repositoryUrl ) |
repositoryUrl | repository.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 Name | Type | Default Value | Description |
---|---|---|---|
classesDir | File | null | The directory that contains the compiled classes. It sets the value of the build.outputDirectory element in the generated pom.xml file. |
configurationScopeMappings | Map<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. |
forcedExclusions | Set<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. |
goalPrefix | String | null | The 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. |
mavenDebug | boolean | false | Whether to invoke the Maven Embedder in debug mode. |
mavenEmbedderClasspath | FileCollection | null | The classpath used to invoke the Maven Embedder. |
mavenEmbedderMainClassName | String | "org.apache.maven.cli.MavenCli" | The Maven Embedder’s main class name. |
mavenPluginPluginVersion | String | "3.4" | The version of the Maven Plugin Plugin to use to generate the plugin descriptor for the project. |
mavenSettingsFile | File | null | The custom settings.xml file to use. It sets the --settings argument on the Maven Embedder invocation. |
outputDir | File | null | The directory where the Maven plugin descriptor files are saved. |
pomArtifactId | String | null | The 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. |
pomGroupId | String | null | The universally unique identifier for the project. It sets the value of the project.groupId element in the generated pom.xml file. |
pomRepositories | Map<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. |
pomVersion | String | null | The version of the artifact produced by this project. It sets the value of the project.version element in the generated pom.xml file. |
sourceDir | String | null | The directory that contains the source files. It sets the value of the build.sourceDirectory element in the generated pom.xml file. |
useSetterComments | boolean | true | Whether 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
Method | Description |
---|---|
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, ?> pomRepositories | Adds 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 Name | Type | Default Value | Description |
---|---|---|---|
localRepositoryDir | String | null | The directory of the system’s local repository. It sets the value of the localRepository element in the generated settings.xml file. |
nonProxyHosts | String | null | The 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. |
outputFile | File | null | The generated settings.xml file. |
proxyHost | String | null | The host name or address of the proxy server. It sets the value of the proxies.proxy.host element in the generated settings.xml file. |
proxyPassword | String | null | The 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. |
proxyPort | String | null | The port number of the proxy server. It sets the value of the proxies.proxy.port element in the generated settings.xml file. |
proxyUser | String | null | The 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. |
repositoryUrl | String | null | The 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