Java project with Maven

A simple example of a pipeline for 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 jdk-8.

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

Stages:

  • deps — get all required dependencies so it doesn’t count as duration of 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 September 17, 2020