Mastodon

How to use JDK 1.8u45 in travis or "cannot find symbol" while building Java 1.8u45

While building one of my repositories with Shippable, I got the following error:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/shippable/workspace/src/github.com/stevenschwenke/Java8Workshop/src/test/java/de/stevenschwenke/java/java8workshop/C_09_JavaFX.java:[193,13] cannot find symbol
symbol: class Alert
location: class de.stevenschwenke.java.java8workshop.C_09_JavaFX
[ERROR] /home/shippable/workspace/src/github.com/stevenschwenke/Java8Workshop/src/test/java/de/stevenschwenke/java/java8workshop/C_09_JavaFX.java:[193,31] cannot find symbol
symbol: class Alert
location: class de.stevenschwenke.java.java8workshop.C_09_JavaFX
[ERROR] /home/shippable/workspace/src/github.com/stevenschwenke/Java8Workshop/src/test/java/de/stevenschwenke/java/java8workshop/C_09_JavaFX.java:[193,42] package Alert does not exist
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

Solution for travis

See Travis issue 4042. Adding the lines 10 to 13 into your .travis.yml seems to cause Travis to use a newer JDK version:

addons:
# language
language: java

# version numbers
jdk:
- oraclejdk8

# Use JDK 8u45. The above line just causes the use of a minor version of Java 8.
addons:
apt:
packages:
- oracle-java8-installer

That caused my build to run just fine in travis.

Solution for shippable

Unfortunately, I don’t know a solution for Shippable right now. However, you can view the progress in this bug report of mine.

Update

Using a custom image as described in the mentioned ticket, I got my build working. This is my shippable.yml:

# language
language: java

# version numbers
jdk:
- oraclejdk8

before_install:
- apt-get update
- apt-get install -y maven

before_script:
- if [[ $SHIPPABLE_JDK_VERSION == "oraclejdk8" ]] ; then export JAVA_HOME="/usr/lib/jvm/java-8-oracle"; export PATH="$PATH:/usr/lib/jvm/java-8-oracle/bin"; export java_path="/usr/lib/jvm/java-8-oracle/jre/bin/java"; fi
- update-alternatives --set java $java_path
- java -version

after_success:
- mvn clean cobertura:cobertura
- mvn test

TL;DR

Both Travis and Shippable are able to build Java 1.8u45 code, however not out of the box.