From 642a4ff24097226d56040909b27555ad4fa1b1ef Mon Sep 17 00:00:00 2001 From: Andrzej Janczak Date: Thu, 20 Aug 2026 10:02:24 +0200 Subject: [PATCH 1/2] feature: skip the openjdk install when the JVM is already on the image Problem: every sbt job spends ~44 MB and tens of seconds on `apt install openjdk-N-jre`. The machine images already carry JDK 8, 17 and 21, so apt was only upgrading an installed package (17.0.13 -> 17.0.15 on ubuntu-2004). Fix: install only when the JVM directory is absent, and always switch the default. JDK 11 is the only version genuinely missing from the images. --- src/jobs/sbt.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/jobs/sbt.yml b/src/jobs/sbt.yml index 9185df59..402cbfbc 100644 --- a/src/jobs/sbt.yml +++ b/src/jobs/sbt.yml @@ -89,9 +89,15 @@ steps: environment: OJDK_VERSION: << parameters.openjdk_version >> command: | - sudo apt update - sudo apt install openjdk-${OJDK_VERSION}-jre - sudo update-alternatives --set java /usr/lib/jvm/java-${OJDK_VERSION}-openjdk-amd64/bin/java + JVM_DIR="/usr/lib/jvm/java-${OJDK_VERSION}-openjdk-amd64" + # machine images already carry 8, 17 and 21; apt would only upgrade them + if [ -d "$JVM_DIR" ]; then + echo "openjdk-${OJDK_VERSION} already present at ${JVM_DIR}, skipping install" + else + sudo apt update + sudo apt install -y "openjdk-${OJDK_VERSION}-jre" + fi + sudo update-alternatives --set java "${JVM_DIR}/bin/java" - when: condition: << parameters.install_sbt_version >> steps: From 08098babb1fe0df3a887c53693497d203c78418a Mon Sep 17 00:00:00 2001 From: Andrzej Janczak Date: Thu, 20 Aug 2026 10:47:15 +0200 Subject: [PATCH 2/2] fix: guard on the registered alternative, not the directory A directory can exist without update-alternatives knowing about it, and the --set below would then fail. Testing the alternative tests the actual precondition. --- src/jobs/sbt.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jobs/sbt.yml b/src/jobs/sbt.yml index 402cbfbc..9b905f42 100644 --- a/src/jobs/sbt.yml +++ b/src/jobs/sbt.yml @@ -90,9 +90,9 @@ steps: OJDK_VERSION: << parameters.openjdk_version >> command: | JVM_DIR="/usr/lib/jvm/java-${OJDK_VERSION}-openjdk-amd64" - # machine images already carry 8, 17 and 21; apt would only upgrade them - if [ -d "$JVM_DIR" ]; then - echo "openjdk-${OJDK_VERSION} already present at ${JVM_DIR}, skipping install" + # skip only when the exact alternative the --set below needs is already registered + if update-alternatives --list java 2>/dev/null | grep -qx "${JVM_DIR}/bin/java"; then + echo "openjdk-${OJDK_VERSION} already registered at ${JVM_DIR}, skipping install" else sudo apt update sudo apt install -y "openjdk-${OJDK_VERSION}-jre"