Skip to main content

Managing Java versions

Abstract

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.

  1. Add the Set Java version Step to your Workflow. We recommend setting it as the first Step of the Workflow.

  2. Find the Java version to be set globally for the build input.

  3. Set it to the version you need.

    The options are:

    • 8

    • 11 (the default value)

    • 17

    • 21

Example 1. YAML example

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.

  1. Log in to Bitrise and select Bitrise CI on the left, then select your project.

  2. Click the Workflows button on the main page.

  3. Add the Script Step to your Workflow.

  4. 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 and java-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"    
  5. Start a new build. This Script Step can be the very first Step in the Workflow, as it does not depend on anything else.