# Java
# Setting up your first CI pipeline
Delta CI expects a .delta.yml
file in your reposity to read your CI config from.
# Maven
For Maven-based projects, we recommend using the official maven java image
docker: maven:3-openjdk-8
steps:
- mvn package
- mvn verify
2
3
4
For Java & other JVM-based projects, we recommend using a docker image as an execution environment. In the example, we are using the official image from maven. Depends on your build system & your JVM version, you might also want to use other images.
Here we listed some common images for you to use with:
JVM | Maven Version | Image |
---|---|---|
OpenJDK 8 | maven 3.6 | maven:3.6-openjdk-8 (opens new window) |
OpenJDK 11 | maven 3.6 | maven:3.6-openjdk-11 (opens new window) |
Amazon Corretto 8 | maven 3.6 | maven:3.6-amazoncorretto-8 (opens new window) |
# Gradle
For Gradle based projects, we recommend using Gradle wrapper in an official OpenJDK (opens new window) image to make sure you are using the correct Gradle version, for example:
docker: openjdk:11
steps:
- ./gradlew assemble
- ./gradlew check
2
3
4
If you want to use another version of OpenJDK or a different JVM, we listed some common images for you to use with:
JVM Distribution | Version | Image |
---|---|---|
OpenJDK | 8 | maven:3.6-openjdk-8 (opens new window) |
OpenJDK | maven 3.6 | maven:3.6-openjdk-11 (opens new window) |
Amazon Corretto 8 | maven 3.6 | maven:3.6-amazoncorretto-8 (opens new window) |
# Run your config first time
Once you have committed your .delta.yml
file into your git repo and pushed it. Delta CI will start executing it immediately. During the first run, it will need to download the docker image as well as Java dependencies. Once you have finished the first run, all subsequent runs will be much faster.
As you may have noticed, there's no caching setup in the config. Unlike other CIs, we don't require you to configure it yourself. Instead, we just keep the disk persist between build runs, just like your dev environment.
By default, maven and Gradle will try to skip tests that are not changed since the last run. Depends on your use case, that is not always desired behavior. If you would like to always run the build & tests from scratch, consider adding an mvn clean
or ./gradlew clean
command as the first step.
# Running multiple jobs at once
In our previous example, we defined only one job. If you want to run multiple jobs from a single push, you could define a workflow with multiple jobs and also define dependencies between them. To do so, you could write .delta.yml
as such.
jobs:
build:
docker:
test:
deploy:
2
3
4
5
# Environment Variables
There are two ways to set the environment variable with Delta CI. Normally you set the env vars under your job in the .delta.yml config. If you want the env var to be a secret, you simply head over to the Workflows page in the dashboard and set them there. More about that further down. Note that the environment variables will only be available to the steps in the job you defined them in, not globally.
# Example with environment variables
jobs:
"Test and Build":
docker: maven:3-openjdk-8
env:
SENTRY_ORG: "delta-ci"
SENTRY_PROJECT: "delta-api"
steps:
- ./gradlew test
- ./gradlew build
2
3
4
5
6
7
8
9
# Allocate more hardware resource for a job
By default, we allocate 2vCPU and 4 GB of RAM for each job. Depends on your use case, you might want to adjust it. You have full control over the allocation as long as you don't exceed your maximum allowance.
docker: openjdk:11
machine:
vcpu: 8
ram: 16GB
steps:
- ./gradlew assemble
- ./gradlew check
2
3
4
5
6
7