DISCLAIMER
By using this script you agree to the license agreement specified for all versions of the Oracle JDK you invoke this script for. The author(s) assume no responsibility for compliance with the Oracle JDK license agreement. Please see LICENSE for additional conditions of use.
Provides automatic download, unpacking and usage of specific Oracle JDK versions to faciliate repeatable builds of Java based software.
Simply set your desired JDK version and wrap your command relying on the JDK with a call to the jdk-wrapper.sh script.
> JDKW_VERSION=8u121 JDKW_BUILD=b13 JDKW_TOKEN=e9e7ea248e2c4826b92b3f075a80e441 jdk-wrapper.sh <CMD>
Alternatively, create a .jdkw properties file in the working directory.
JDKW_VERSION=8u121
JDKW_BUILD=b13
JDKW_TOKEN=e9e7ea248e2c4826b92b3f075a80e441
Then execute jdk-wrapper.sh script without setting the environment variables.
> jdk-wrapper.sh <CMD>
The third option is to pass arguments to jdk-wrapper.sh which define the configuration. Any argument that begins with "JDKW_" will be considered a configuration parameter, everything from the first non-configuration parameter onward is considered part of the command.
> jdk-wrapper.sh JDKW_VERSION=8u121 JDKW_BUILD=b13 JDKW_TOKEN=e9e7ea248e2c4826b92b3f075a80e441 <CMD>
Finally, any combination of these three forms of configuration is permissible. Any environment variables override the values in the .jdkw file and any values specified on the command line override both the environment and the .jdkw file.
The wrapper script will download and cache the specified JDK version and set JAVA_HOME appropriately before executing the specified command.
Regardless of how the configuration is specified it supports the following:
- JDKW_VERSION : Version identifier (e.g. '8u65'). Required.
- JDKW_BUILD : Build identifier (e.g. 'b17'). Required.
- JDKW_TOKEN : Download token (e.g. e9e7ea248e2c4826b92b3f075a80e441). Optional.
- JDKW_JCE : Include Java Cryptographic Extensions (e.g. false). Optional.
- JDKW_TARGET : Target directory (e.g. '/var/tmp'). Optional.
- JDKW_PLATFORM : Platform specifier (e.g. 'linux-x64'). Optional.
- JDKW_EXTENSION : Archive extension (e.g. 'tar.gz'). Optional.
- JDKW_VERBOSE : Log wrapper actions to standard out. Optional.
The default target directory is ~/.jdk.
The default platform is detected using uname.
By default the Java Cryptographic Extensions are included.
By default the extension dmg is used for Darwin and tar.gz for other platforms.
By default the wrapper does not log.
IMPORTANT: The JDKW_TOKEN is required for release 8u121-b13 and newer.
The desired version and build of the Oracle JDK may be determined as follows:
- Browse to the Java SE Downloads page.
- Click the "JDK Download" button on the right.
- Locate the desired version.
- Accept the associated license agreement.
- Hover over one of the download links.
All the links contain a path element named {MAJOR}u{MINOR}-{BUILD}, for example 8u73-b02 where 8u73 would be used as the value for JDKW_VERSION and b02 the value for JDKW_BUILD. For versions 8u121-b13 and higher the link contains an alpha-numeric path segment that looks like e9e7ea248e2c4826b92b3f075a80e441 which needs to be set as the JDKW_TOKEN.
Archived versions of JDK8 are listed here.
The Oracle JDK versions specified over all invocations of the jdk-wrapper.sh script are cached in the directory specified by JDKW_TARGET environment variable in perpetuity. It is recommended that you purge the cache periodically to prevent it from growing unbounded.
There are three changes necessary to use the jdk-wrapper.sh script in your Travis build. First, ensure that the JDKW_TARGET is configured as a cache directory:
cache:
directories:
- $HOME/.jdk
Second, configure the JDKW_VERSION and JDKW_BUILD environment variables to specify the Oracle JDK to use:
env:
global:
- JDKW_VERSION=8u121
- JDKW_BUILD=b13
- JDKW_TOKEN=e9e7ea248e2c4826b92b3f075a80e441
To create a matrix build against multiple versions of the Oracle JDK simply specify the environment variables like this:
env:
- JDKW_VERSION=7u79 JDKW_BUILD=b15
- JDKW_VERSION=8u121 JDKW_BUILD=b13 JDKW_TOKEN=e9e7ea248e2c4826b92b3f075a80e441
Finally, invoke your build command using the jdk-wrapper script. The following assumes you have downloaded and included jdk-wrapper.sh in your project.
script:
- ./jdk-wrapper.sh mvn install
Alternatively, you may download the latest version and execute it as follows:
script:
- curl -s https://raw.githubusercontent.com/vjkoskela/jdk-wrapper/master/jdk-wrapper.sh | bash /dev/stdin mvn install
If your repository contains a .jdkw properties file it is not sufficient to set the environment variables to create a matrix build because the .jdkw properties file will override the environment variables. Instead you must set the environment variables and then pass them as arguments to jdk-wrapper.sh as follows:
script:
- ./jdk-wrapper.sh JDKW_VERSION=${JDKW_VERSION} JDKW_BUILD=${JDKW_BUILD} JDKW_TOKEN=${JDKW_TOKEN} mvn install
This is most commonly the case when you have a JDK version that you develop against (typically the latest) specified in .jdkw but desire a build which validates against multiple (older) JDK versions.
Published under Apache Software License 2.0, see LICENSE
© Ville Koskela, 2016