How to use Gitlab CI to build a Java Maven project?

MRK187 picture MRK187 · Oct 30, 2015 · Viewed 71k times · Source

I have been experimenting with no success whatsoever, I am running a Gitlab hosted on Linux, and trying to get my head around the CI functionality.

According to the Gitlab documentation you only need to create a .gitlab-ci.yml file, the Gitlab implementation of Travis-CI. Now from the looks of it you can accomplish a lot with the .gitlab-ci.yml, but a lot of the documentation is referencing Ruby and other languages. Nothing is said about how to build Java Maven projects.

How can I build a simple application in Java? Can I use the shared runner, or should I be using a specific runner, in that case what or which runner implementation should I choose: ssh, docker, or shell? Then, what should I put in the .gitlab-ci.yml file at least to build the project with Maven?

Answer

rolve picture rolve · Jan 8, 2016

Register a Docker runner and use one of the official Maven Docker images, e.g., maven:3-jdk-11 in your .gitlab-ci.yml file:

image: maven:3-jdk-11

build:
  script: "mvn install -B"

Note the -B flag, which is recommended for non-interactive use.

As far as I understand, it does not matter whether the runner is shared or specific.