|
| 1 | +--- |
| 2 | +# Build JAVA applications using Apache Maven (http://maven.apache.org) |
| 3 | +# For docker image tags see https://hub.docker.com/_/maven/ |
| 4 | +# |
| 5 | +# For general lifecycle information see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html |
| 6 | +# |
| 7 | +# This template will build and test your projects as well as create the documentation. |
| 8 | +# |
| 9 | +# * Caches downloaded dependencies and plugins between invocation. |
| 10 | +# * Does only verify merge requests but deploy built artifacts of the |
| 11 | +# master branch. |
| 12 | +# * Shows how to use multiple jobs in test stage for verifying functionality |
| 13 | +# with multiple JDKs. |
| 14 | +# * Uses site:stage to collect the documentation for multi-module projects. |
| 15 | +# * Publishes the documentation for `master` branch. |
| 16 | + |
| 17 | +variables: |
| 18 | + # This will supress any download for dependencies and plugins or upload messages which would clutter the console log. |
| 19 | + # `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work. |
| 20 | + MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true" |
| 21 | + # As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used |
| 22 | + # when running from the command line. |
| 23 | + # `installAtEnd` and `deployAtEnd`are only effective with recent version of the corresponding plugins. |
| 24 | + MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true" |
| 25 | + |
| 26 | +# Cache downloaded dependencies and plugins between builds. |
| 27 | +# To keep cache across branches add 'key: "$CI_JOB_REF_NAME"' |
| 28 | +cache: |
| 29 | + paths: |
| 30 | + - .m2/repository |
| 31 | + |
| 32 | +# This will only validate and compile stuff and run e.g. maven-enforcer-plugin. |
| 33 | +# Because some enforcer rules might check dependency convergence and class duplications |
| 34 | +# we use `test-compile` here instead of `validate`, so the correct classpath is picked up. |
| 35 | +.validate: &validate |
| 36 | + stage: build |
| 37 | + script: |
| 38 | + - 'mvn $MAVEN_CLI_OPTS test-compile' |
| 39 | + |
| 40 | +# For merge requests do not `deploy` but only run `verify`. |
| 41 | +# See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html |
| 42 | +.verify: &verify |
| 43 | + stage: test |
| 44 | + script: |
| 45 | + - 'mvn $MAVEN_CLI_OPTS verify site site:stage' |
| 46 | + except: |
| 47 | + - master |
| 48 | + |
| 49 | +# Validate merge requests using JDK7 |
| 50 | +validate:jdk7: |
| 51 | + <<: *validate |
| 52 | + image: maven:3.3.9-jdk-7 |
| 53 | + |
| 54 | +# Validate merge requests using JDK8 |
| 55 | +validate:jdk8: |
| 56 | + <<: *validate |
| 57 | + image: maven:3.3.9-jdk-8 |
| 58 | + |
| 59 | +# Verify merge requests using JDK7 |
| 60 | +verify:jdk7: |
| 61 | + <<: *verify |
| 62 | + image: maven:3.3.9-jdk-7 |
| 63 | + |
| 64 | +# Verify merge requests using JDK8 |
| 65 | +verify:jdk8: |
| 66 | + <<: *verify |
| 67 | + image: maven:3.3.9-jdk-8 |
| 68 | + |
| 69 | + |
| 70 | +# For `master` branch run `mvn deploy` automatically. |
| 71 | +# Here you need to decide whether you want to use JDK7 or 8. |
| 72 | +# To get this working you need to define a volume while configuring your gitlab-ci-multi-runner. |
| 73 | +# Mount your `settings.xml` as `/root/.m2/settings.xml` which holds your secrets. |
| 74 | +# See https://maven.apache.org/settings.html |
| 75 | +deploy:jdk8: |
| 76 | + # Use stage test here, so the pages job may later pickup the created site. |
| 77 | + stage: test |
| 78 | + script: |
| 79 | + - 'mvn $MAVEN_CLI_OPTS deploy site site:stage' |
| 80 | + only: |
| 81 | + - master |
| 82 | + # Archive up the built documentation site. |
| 83 | + artifacts: |
| 84 | + paths: |
| 85 | + - target/staging |
| 86 | + image: maven:3.3.9-jdk-8 |
| 87 | + |
| 88 | + |
| 89 | +pages: |
| 90 | + image: busybox:latest |
| 91 | + stage: deploy |
| 92 | + script: |
| 93 | + # Because Maven appends the artifactId automatically to the staging path if you did define a parent pom, |
| 94 | + # you might need to use `mv target/staging/YOUR_ARTIFACT_ID public` instead. |
| 95 | + - mv target/staging public |
| 96 | + dependencies: |
| 97 | + - deploy:jdk8 |
| 98 | + artifacts: |
| 99 | + paths: |
| 100 | + - public |
| 101 | + only: |
| 102 | + - master |
0 commit comments