Skip to content

Index

sdkman::init

Initialize SDKMAN for the calling subshell so the sdk function is available. Shell options and traps are not function-scoped, so everything this does lands in the caller. That is the point — but it also means it MUST be called from inside a ( ... ) subshell, or the strict-mode relaxation leaks into the rest of the script. It dies rather than allow that.

Typical use:

Subshell required: sdkman::init relaxes strict mode, which must not leak past the sdk calls.

( sdkman::init sdkman_jdks::get_available_tem_jdk_major_versions )

Function has no arguments.

Exit codes

  • 0: SDKMAN initialized in the calling subshell
  • 1: called outside a subshell

sdkman::clean_output

Strip ANSI escape codes and blank lines from stdin (used to clean sdk command output). Output: stdout — cleaned text shellcheck disable=SC2120 # called with no args by callers, shellcheck can't see all call sites

Function has no arguments.

sdkman::update_metadata

Refresh SDKMAN metadata (runs 'sdk update' and cleans output). shellcheck disable=SC2120 # called with no args by callers, shellcheck can't see all call sites

Function has no arguments.

sdkman::find_sdkmanrc_file

Print the path of the nearest .sdkmanrc file at or above a directory. Walks from the given directory up to / and prints the first .sdkmanrc found. SDKMAN's own auto_env consults only the directory being entered, so a build started in a submodule — or in any non-interactive shell — sees no pin at all; this is what recovers it.

Arguments

  • $1 (start_dir): directory to start the upward search from

Exit codes

  • 0: always — "none found" is signalled by empty stdout, never a non-zero status

Output on stdout

  • path of the nearest .sdkmanrc, or nothing when no ancestor holds one

sdkman::get_sdkmanrc_file_value

Print the value assigned to a key in an .sdkmanrc file. Tolerant of what a hand-edited file picks up: CRLF line endings, blank lines, whole-line and trailing # comments, and whitespace around the key, the =, and the value. A later assignment of the same key wins, matching how a shell reading the file would resolve it. Uses awk -v (not --assign) because mawk — the default awk on Debian/Ubuntu — rejects the long form.

Arguments

  • $1 (sdkmanrc_file): path to the .sdkmanrc file
  • $2 (key): candidate name to look up (e.g. java)

Exit codes

  • 0: always — "absent" is signalled by empty stdout, never a non-zero status
  • 1: the given file does not exist

Output on stdout

  • the assigned value, or nothing when the key is absent or assigned an empty value

sdkman::sdkmanrc_java_home

Resolve the JDK pinned by the nearest .sdkmanrc to an absolute JAVA_HOME path. Prints nothing — a deliberate no-op — when no ancestor holds an .sdkmanrc, when that file declares no java= key, or when the pinned JDK is not installed. Warning rather than failing on an uninstalled pin is deliberate: pins go stale (that is what sdkman::rewrite_sdkmanrc_file_java_version exists for), and a wrapper that refuses to run Maven over a stale pin is worse than one that falls back to the inherited JDK and says so.

Arguments

  • $1 (start_dir): directory to start the upward .sdkmanrc search from

Exit codes

  • 0: always — "nothing to apply" is signalled by empty stdout, never a non-zero status

Output on stdout

  • absolute path of the pinned JDK's SDKMAN candidate directory, or nothing

Output on stderr

  • a log::warn line when the pinned JDK is not installed

sdkman::get_sdkmanrc_file_java_artifact_id

Print the java artifact ID declared in an .sdkmanrc file. A named shorthand for the java key; sdkman::get_sdkmanrc_file_value owns the parsing, so this accepts everything that does — CRLF, comments, whitespace around the =.

Arguments

  • $1 (sdkmanrc_file): .sdkmanrc file path

Exit codes

  • 0: always — "absent" is signalled by empty stdout, never a non-zero status
  • 1: the given file does not exist

Output on stdout

  • artifact ID string (e.g. "21.0.3-tem"), or nothing when no java key is declared

sdkman::overwrite_sdkmanrc_file_java_artifact_id

Overwrite the java artifact ID in an .sdkmanrc file. Matches the same line shapes sdkman::get_sdkmanrc_file_value reads — leading whitespace and whitespace around the = — and rewrites only the value, preserving indentation, spacing, a trailing comment, and a CRLF line ending. Read and write MUST stay symmetric: a reader that finds a line the writer cannot match turns sdkman::rewrite_sdkmanrc_file_java_version into a silent no-op that reports success.

Arguments

  • $1 (sdkmanrc_file): .sdkmanrc file path
  • $2 (artifact_id): new artifact ID (e.g. "21.0.3-tem")

Exit codes

  • 1: the given file does not exist

sdkman::rewrite_sdkmanrc_file_java_version

Update the java entry in an .sdkmanrc file to the latest installed Temurin JDK for the same major version. No-ops if the currently declared artifact is already installed.

Arguments

  • $1 (.sdkmanrc): file path

sdkman::list_all_sdkmanrc_files

Find and print the paths of all .sdkmanrc files under $HOME. Output: stdout — sorted list of .sdkmanrc file paths, one per line shellcheck disable=SC2120 # called with no args by callers, shellcheck can't see all call sites

Function has no arguments.

sdkman::rewrite_sdkmanrc_file_java_versions

Update the java entry in every .sdkmanrc file found under $HOME. shellcheck disable=SC2120 # called with no args by callers, shellcheck can't see all call sites

Function has no arguments.