Skip to content
Latchkey

SDKMAN!: Install Java and Gradle Non-Interactively in CI

SDKMAN! is a shell-function tool: source sdkman-init.sh, set sdkman_auto_answer=true, then sdk install java <ver> runs without interactive prompts.

SDKMAN! installs JVM ecosystem SDKs. Like nvm it is a sourced shell function, and by default it prompts (e.g. to set a version as default), which hangs CI unless you disable prompts.

What it does

SDKMAN! installs and switches JVM SDKs (Java distributions, Gradle, Maven, Kotlin, Scala, sbt) under $SDKMAN_DIR. sdk install <candidate> <version> fetches and activates a version; sdk use switches the current shell. The sdk command is a function defined by sdkman-init.sh.

Common usage

bash
export SDKMAN_DIR="$HOME/.sdkman"
# disable prompts for CI
echo "sdkman_auto_answer=true" >> "$SDKMAN_DIR/etc/config"
source "$SDKMAN_DIR/bin/sdkman-init.sh"
sdk install java 21.0.3-tem
sdk install gradle 8.7
java -version && gradle -v

Options

Command / settingWhat it does
sdk install <c> <v>Install a candidate version
sdk use <c> <v>Switch this shell to a version
sdk default <c> <v>Set the default version
sdkman_auto_answer=trueAnswer prompts automatically (config file)
sdkman_selfupdate_feature=falseDisable self-update nag in CI
source $SDKMAN_DIR/bin/sdkman-init.shDefine the sdk function

In CI

Set sdkman_auto_answer=true before installing or the first install prompts "Do you want it set as default?" and the job hangs. Source sdkman-init.sh in every step because the function is not on PATH. Cache $SDKMAN_DIR/candidates to skip re-downloading SDKs.

Common errors in CI

"sdk: command not found" means sdkman-init.sh was not sourced in this shell. A job that hangs at install is waiting on a prompt; set sdkman_auto_answer=true. "Stop! java X.Y is not available." means a wrong version string; run sdk list java for the exact identifiers (e.g. 21.0.3-tem). "Done installing!" but java -version wrong means a later step did not re-source init.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →