SDKMAN - a handy tool

SDKMAN - a handy tool
Photo by Dan Cristian Pădureț / Unsplash

From sdkman website:

💡
Meet SDKMAN! – your reliable companion for effortlessly managing multiple Software Development Kits on Unix systems

There are a lot of SDKs supported by SDKMAN!: Java, Groovy, Kotlin, Scala, Gradle, Maven, Leiningen, Micronaut, Grails, Vert.x, JBake, AsciidoctorJ...

Quickstart

curl -s "https://get.sdkman.io" | bash

sdkman will be installed under ~/.sdkman directory.

Manage multiple versions

Install multiple JDK

# list all supported JDK versions
sdk list java

sdk install java 8.0.382-amzn
sdk install java 11.0.18-amzn

# set default java version
sdk default java 8.0.382-amzn

Install multiple version of Maven

# list all supported maven versions
sdk list maven

sdk install maven 3.6.3
sdk install maven 3.9.4

# set default maven version
sdk default maven 3.9.4

Switch versions of multiple tools

Go to the project root directory:

sdk env init

This will create the .sdkmanrc file in the current directory if it does not exists.

Edit the file, define the versions of the tools used by our project, for example:

# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=8.0.382-amzn
maven=3.9.4

Activate the versions of the tools define in .sdkmanrc file in the current directory

sdk env

The output will look like this:

Using java version 8.0.382-amzn in this shell.

Using maven version 3.9.4 in this shell.

This is quick and handy to ensure the tools in the project configured properly 👍.

Auto invoke sdk env

Edit the sdkman default config file $HOME/.sdkman/etc/config, add or edit the following line:

sdkman_auto_env=true

When we change directory to our project which contains .sdkmanrc file, sdkman will automatically invoke the sdk env to configured tool versions for us! Great 👏.