Maven Use plugin¶
The Maven Use plugin packages Maven-based projects and, unlike the Maven plugin, deploys the artifact to an internal Maven repository. From this repository, the artifacts can be accessed by any other parts using the Maven or Maven Use plugins.
Keys¶
This plugin has no unique keys.
Attributes¶
This plugin supports the self-contained
build attribute. Declaring this attribute
prevents access to the default Maven Central repository. All dependencies, including
plugins, must then be provided as build packages or in an earlier part.
When this attribute is declared, Maven Use may rewrite the version specification of project dependencies based on what is locally available. This can be avoided by provisioning the specified version prior to build time — for example, by building it with the Maven Use plugin in an earlier part.
Dependencies¶
The Maven plugin needs the mvn
executable to build Maven projects but does not
provision it to allow flexibility in the choice of version.
To provide mvn
, one can either specify the maven
Ubuntu package as a
build-package
or define a maven-deps
part. In the latter case, all
parts using Maven should declare that they come after the maven-deps
part. The
plugin will then assume that the maven-deps
part staged the mvn
executable to
be used in the build step. This can be useful, for example, in cases where a specific,
unreleased version of Maven is desired but unavailable as a snap or Ubuntu package.
How it works¶
During the build step the plugin performs the following actions:
Creates a Maven settings file that configures proxy settings, points to the local Maven repository created by Craft Parts, and, if the
self-contained
build attribute is declared, disables network connections.Updates any of the project’s
pom.xml
files to deploy the final artifacts to the local repository.Calls
maven deploy
to build and deploy the project to the local repository.
Examples¶
The following snippet declares two parts: java-dep
, which uses the maven-use
plugin, and java-main
. Before java-main
can build, the contents of java-dep
must be staged. This dependency is handled by declaring that java-main
must build
after
the java-dep
part.
parts:
java-dep:
source: dep/
plugin: maven-use
build-packages:
- maven
java-main:
source: main/
plugin: maven
build-packages:
- maven
after:
- java-dep
The following snippet declares two parts: java-jacoco
, which uses the maven-use
plugin, and java-main
. To restrict access to the Maven Central repository, both
parts declare the self-contained
build attribute. The pom.xml
file of
java-main
declares java-jacoco
as a dependency, which is handled by declaring
that java-main
must build after
the java-jacoco
part.
parts:
java-jacoco:
source: https://github.com/jacoco/jacoco.git
plugin: maven-use
build-packages:
- maven
build-attributes:
- self-contained
java-main:
source: .
plugin: maven
build-packages:
- maven
build-attributes:
- self-contained
after:
- java-jacoco