Historically Java releases moved at a slow pace. Open source projects and companies could comfortably stay on the same version for several years. Recently the release cadence has quickened with Java’s new six-monthly release schedule. Starting with Java 9, a new version is released every six months. Now many applications and projects need to support a wide range of Java versions.

It is important to test against all of these JDK’s to make sure that regressions don’t creep in. If you’re using Travis CI for continuous integration, you can easily test against a wide range of JDK’s with their jdk configuration key. This uses their build matrix feature to run the same set of tests against each entry in the build matrix.

To build and test your Java or JVM based project against multiple JDKs, add each JDK you’d like to test to the jdk key in your .travis.yml file:

jdk:
  - oraclejdk8
  - oraclejdk9
  - oraclejdk11
  - openjdk8
  - openjdk-ea

Available JDK’s

JDK’s are downloaded from jdk.java.net. You can use oraclejdkN or openjdkN where N is the JDK version number, e.g. oraclejdk10 or openjdk8. You can also run tests against the latest early access builds using oraclejdk-ea and openjdk-ea. The JDK’s are downloaded by the install-jdk.sh script.

The full list of available JDKs is:

  • oraclejdk7
  • oraclejdk8
  • oraclejdk9
  • oraclejdk10
  • oraclejdk11
  • openjdk7
  • openjdk8
  • openjdk9
  • openjdk10
  • openjdk11
  • openjdk-ea

Testing against this many JDK’s is probably wasteful of Travis CI’s resources. For most projects there are no differences between Oracle’s JDK and OpenJDK. We would recommend picking either Oracle’s JDK or OpenJDK to run tests against all of the versions. With the other JDK you probably only need to test the current long term support release, feature release, and early access release.

jdk:
  - openjdk8
  - openjdk11
  - openjdk-ea
  - oraclejdk8
  - oraclejdk11
  - oraclejdk-ea

Ignoring failures with pre-release JDK’s

You may want to test against newer JDK’s but are not ready to support them. Travis CI lets you define certain builds as being allowed to fail. To test against early access builds of Open JDK without breaking the build if the tests fail, add the allow_failures key to your matrix in the travis.yml file.

jdk:
  - openjdk11
  - openjdk-ea

matrix:
  allow_failures:
    - jdk: openjdk-ea

Certificate Issues

When using openjdk9 and above you may encounter certificate errors downloading from some repositories, notably Clojars. This error can look something like this:

Could not transfer artifact ring:ring-codec:jar:1.0.1 from/to clojars (https://repo.clojars.org/):
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

To fix this, you need to configure Java to use the system certificate store instead of the less complete OpenJDK certificate store. Oracle’s JDK ships with more certificates in the store, so doesn’t suffer from the same problems.

jdk:
  - openjdk8
  - oraclejdk8
  - oraclejdk9

matrix:
  include:
    - jdk: openjdk10
      before_install:
        - rm "${JAVA_HOME}/lib/security/cacerts"
        - ln -s /etc/ssl/certs/java/cacerts "${JAVA_HOME}/lib/security/cacerts"