Reputation: 9072
I would like to run my Circle CI 2.0 build using Open JDK 8 & 9. Are there any YAML examples available explaining how to build a Java project using multiple JDK versions?
Currently I trying to add an new job java-8
to my build. But I do not want to repeat all the step of my default Java 9 build
job. Is there a DRY approach for this?
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:9-jdk
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx1g
TERM: dumb
steps:
- checkout
# Run all tests
- run: gradle check
java-8:
- image: circleci/openjdk:8-jdk
Upvotes: 2
Views: 822
Reputation: 21976
I'm sharing my own solution for this problem.
The basic routing is using workflows
version: 2
jobs:
jdk8:
docker:
- image: circleci/openjdk:8-jdk-stretch
steps:
- ...
jdk11:
docker:
- image: circleci/openjdk:11-jdk-stretch
steps:
- ...
workflows:
version: 2
work:
jobs:
- jdk8
- jdk11
Now we can use the way explained on the accepted anser.
version: 2
shared: &shared
steps:
- checkout
- restore_cache:
key: proguard-with-maven-example-{{ checksum "pom.xml" }}
- run: mvn dependency:go-offline
- save_cache:
paths:
- ~/.m2
key: proguard-with-maven-example-{{ checksum "pom.xml" }}
- run: mvn package
jobs:
jdk8:
docker:
- image: circleci/openjdk:8-jdk-stretch
<<: *shared
jdk11:
docker:
- image: circleci/openjdk:11-jdk-stretch
<<: *shared
workflows:
version: 2
work:
jobs:
- jdk8
- jdk11
Upvotes: 1
Reputation: 124
You can use YAML anchors to achieve a reasonable DRY approach. For instance, it might look like:
version: 2
shared: &shared
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx1g
TERM: dumb
steps:
- checkout
# Run all tests
- run: gradle check
jobs:
java-9:
docker:
- image: circleci/openjdk:9-jdk
<<: *shared
java-8:
docker:
- image: circleci/openjdk:8-jdk
<<: *shared
Upvotes: 6