Skip to content

Maven

In case you want to build a Java project, we provide a Docker image for a Java Maven build.

To use this image in a .gitlab-ci.yml file, you can specify a build stage to build a JAR file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
stages:
- build

variables:
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"

cache:
paths:
- .m2/repository

build_jar:
stage: build
image: registry.lakedrops.com/docker/maven-build/maven
script:
- mvn clean verify -s ci_settings.xml
  artifacts:
  name: your_artifact_name
  paths:
- your_artifact_path

In the script section you can execute any Maven build step. The -s ci_settings.xml option is a proper way to pass a suitable settings file, which is committed in VCS.

The variable MAVEN_OPTS should also be set. Here you can specify the local repository the Maven build process should use. This directory is also cached, so we avoid to downloading the third party modules when not necessary.

The created artifact is stored in Gitlab and can be used for deployment.


Last update: March 5, 2021 12:24:55