I am frankly tired of Travis CI's Java builds to fail continuously due to errors in downloading and installing the JDK. As @sormuras pointed out, they are abusing the great install-jdk.sh tool.
The consequences are low reliability for Java builds, which defeat the point of having the continuous integration in place. Plus, currently Java is not supported under Windows.
Time to end this. This project is meant to provide a number of script to be used in Java builds on Travis CI for running Java. The project is focused on Gradle, as it's my favourite tool, but could be of use for Maven, Ant, and SBT users as well.
We rely on Jabba to install the JDK, kudos to them!
Base idea: download the scripts from GitHub and run them.
Here is the relevant part of your .travis.yml
.
Code comments contain relevant details, please read them.
# Java is not yet supported on Windows, so the build would block.
# You do not need any setup from Travis, use a plain bash build
language: bash
# Enable them all, if you need them.
os:
- linux
- osx
- windows
env:
# This is a convenience variable for shortening download commands
- GRAVIS="https://raw.githubusercontent.com/DanySK/Gravis-CI/master/"
matrix:
# List any JDK you want to build your software with.
# You can see the list of supported environments by installing Jabba and using ls-remote:
# https://github.com/shyiko/jabba#usage
- JDK="[email protected]"
- JDK="[email protected]"
before_install:
# Download the script
- curl "${GRAVIS}.install-jdk-travis.sh" --output .install-jdk-travis.sh
# Download, install, configue the JDK, and export the configuration to the current shell
- source ~/.install-jdk-travis.sh
# This is your main script
script:
# Just an example. Do what you deem useful
- ./gradlew clean check --scan --parallel
# If you use Gradle, cleanup the build cache from lock/temporary files
before_cache:
- curl "${GRAVIS}.clean_gradle_cache.sh" --output .clean_gradle_cache.sh
- bash .clean_gradle_cache.sh
cache:
directories:
# This avoids re-downloading the JDK every time, but Travis recommends not to do it
# - $HOME/.jabba/
# If you use Gradle, you may want to save some time with caching
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
I gladly review pull requests and I'm happy to improve the work.
If the software was useful to you, please consider supporting my development activity