-
Pierre Smeyers authoredPierre Smeyers authored
GitLab CI template for Maven
This project implements a generic GitLab CI template for Maven.
It provides several features, usable in different modes (by configuration).
Usage
In order to include this template in your project, add the following to your gitlab-ci.yml
:
include:
- project: 'to-be-continuous/maven'
ref: '2.1.3'
file: '/templates/gitlab-ci-maven.yml'
Global configuration
The Maven template uses some global configuration used throughout all jobs.
Name | description | default value |
---|---|---|
MAVEN_IMAGE |
The Docker image used to run Maven |
maven:latest |
MAVEN_CFG_DIR |
The Maven configuration directory | .m2 |
MAVEN_OPTS |
Global Maven options | -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=${MAVEN_CFG_DIR}/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true |
MAVEN_CLI_OPTS |
Additional Maven options used on the command line | --batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true |
$MAVEN_CFG_DIR
About This variable is used to define the Maven configuration directory. It is used for 2 purposes:
- in case a Maven settings file (
settings.xml
) is found, the template automatically uses it (using the-s
option on command line), - the cache policy declares the
${MAVEN_CFG_DIR}/repository
directory as cached (not to download Maven dependencies over and over again).
If you have a good reason to do differently, you'll have to override the MAVEN_CLI_OPTS
variable as well as the cache
policy.
Jobs
mvn-build
job
The Maven template features a job mvn-build
that performs build and tests at once.
This stage is performed in a single job for optimization purpose (it saves time) and also
for test jobs dependency reasons (some test jobs such as SONAR analysis have a dependency on test results).
It uses the following variable:
Name | description | default value |
---|---|---|
MAVEN_BUILD_ARGS |
Maven arguments for the build & test job | org.jacoco:jacoco-maven-plugin:prepare-agent verify org.jacoco:jacoco-maven-plugin:report |
About Code Coverage
With its default arguments, the GitLab CI template for Maven forces the use of JaCoCo Maven Plugin to compute code coverage during unit tests execution.