Java project with Maven

A simple example of a pipeline for a Java project managed with Maven.

In the following page we’ll build, test, and deploy a Maven project using the official Maven Docker image with OpenJDK 8.

See more info about available Maven images: maven on Docker Hub

Stages:

  • deps — get all required dependencies so that dependency installation doesn’t occur in other stages
  • build — compile Java code
  • test — run unit tests
  • deploy — deploy POM artifacts to the repository
image: maven:3-jdk-8

stages:
  - deps
  - build
  - test
  - deploy

variables:
  # disable maven interactive mode
  MVN_OPTIONS: "-B"

get dependencies:
  stage: deps
  commands:
    - mvn $MVN_OPTIONS dependency:go-offline

compile:
  stage: build
  commands:
    - mvn $MVN_OPTIONS compile

test:
  stage: test
  commands:
    - mvn $MVN_OPTIONS test

deploy:
  stage: deploy
  commands:
    - mvn $MVN_OPTIONS deploy
Last modified October 21, 2020