Managing Java versions
All Bitrise virtual machines have Java 8, Java 11, Java 17, and Java 21 pre-installed. The default version is Java 17 but you can switch versions at any time.
By default, every Bitrise stack comes with Java 11 pre-installed and ready to use. If you do not switch to another version, your build will use Java 11.
In addition to 11, we have two more Java versions pre-installed on all stacks:
-
Java 8
-
Java 17
-
Java 21
You can switch between the versions at any time. You can also install a different Java version (for example, 14).
Potential issues with Java versions
Using a new Java version, or switching Java versions during a build might cause unexpected issues:
Setting Java version with the Set Java version Step
Each Bitrise stack has three different Java versions pre-installed: 8, 11 (the default version), 17, and 21. You can easily switch between the different Java versions with our Set Java version Step. The Step allows you to set the global Java version of the virtual machine that runs your build.
Installing a new Java version
This Step cannot install any Java version. It can only switch between the versions that are pre-installed on our stacks. If you want to install a Java version that is not available on our stacks by default, check out Installing a Java version on an Android stack.
-
Add the Set Java version Step to your Workflow. We recommend setting it as the first Step of the Workflow.
-
Find the Java version to be set globally for the build input.
-
Set it to the version you need.
The options are:
-
8
-
11 (the default value)
-
17
-
21
-
In this example, we're setting the Java version to 17 in the bitrise.yml
file.
primary: steps: - set-java-version@1: inputs: - set_java_version: '17'
Installing a Java version on an Android stack
If you need a Java or JDK version which is not installed on our Android stacks, follow this guide. The example below will install Java/JDK 1.14 with a Script Step. You can adapt it to the version of your choice.
-
Log in to Bitrise and select Bitrise CI on the left, then select your project.
-
Click the
button on the main page. -
Add the Script Step to your Workflow.
-
In the Script content input of the Step, add your script:
The example below installs Java 14 but feel free to replace the
openjdk-14-jdk
andjava-1.14.0-openjdk-amd64
parts with your version of choice.#!/bin/bash set -ex add-apt-repository -y ppa:openjdk-r/ppa apt-get update -qq apt-get install -y openjdk-14-jdk update-java-alternatives -s /usr/lib/jvm/java-1.14.0-openjdk-amd64 echo "done"
-
Start a new build. This Script Step can be the very first Step in the Workflow, as it does not depend on anything else.