How to add the common CI pipelines and pre-commit configuration to an existing Java project¶
The common CI pipeline and Java Maven pipeline templates provide a number of common jobs useful for Java based projects.
This page shows you how to add these jobs to a pipeline for an existing Java project.
Add the CI configuration¶
Update your .gitlab-ci.yml
file and add the following pipeline templates:
include:
- project: "uis/devops/continuous-delivery/ci-templates"
file: "/auto-devops/common-pipeline.yml"
ref: "{replace with the latest ci-templates repository tag}"
- project: "uis/devops/continuous-delivery/ci-templates"
file: "auto-devops-stages.yml"
ref: "{replace with the latest ci-templates repository tag}"
- project: "uis/devops/continuous-delivery/ci-templates"
file: "/auto-devops/maven.gitlab-ci.yml"
ref: "{replace with the latest ci-templates repository tag}"
variables:
# Add this variable if you don't have a Dockerfile in the repository and/or
# want to disable automatic image building.
BUILD_DISABLED: "1"
# Add this variable if your project does not need to run 'mvn deploy'
# to publish build artifacts to a GitLab Maven Repository
MAVEN_DEPLOY_DISABLED: "1"
# Add this variable if your project does not need to run 'mvn verify'
# to run tests in your pipeline
MAVEN_VERIFY_DISABLED: "1"
# Add this variable if you do not need to retrieve GitLab Access Tokens
# used to download Maven dependencies from a configured Maven Repository in GitLab
MAVEN_ACCESS_TOKENS_DISABLED: "1"
If your project needs to retrieve dependencies from a GitLab Maven Repository configured in your
Maven pom.xml, do not add the MAVEN_ACCESS_TOKENS_DISABLED
variable above, and extend the
build job in your .gitlab-ci.yml to use a provided script to retrieve GitLab access tokens:
#add runner tag to maven hidden job
.maven:
tags:
- $GKE_RUNNER_TAG
build:
before_script: !reference [.maven.deploy_tokens]
tags:
- $GKE_RUNNER_TAG
Note that tag value $GKE_RUNNER_TAG
must be added to use a GitLab Runner on GKE which has access to
retrieve secrets from Secrets Manager.
Add the google-java-format pre-commit plugin¶
The google-java-format pre-commit plugin should also be added to the project.
IDE formatter configuration¶
Plugins for the google-java-format code formattter are available for most IDEs - download and install from the following links: