One minute
Managing multiple java versions
Java is now getting new releases at a very fast pace, but many projects are still stuck in Java 8. Each project might be on a different version of Java. I might be using Java 8 for work, but trying out Java 20. We need a painless way to manage multiple versions without messing around with JAVA_HOME manually or with custom scripts. Enter SDKMAN!.
Once the installation is complete, installing different Java versions is as simple as
sdk install java 8.0.372-amzn
sdk install java 17.0.7-amzn
To set Java 8 as default:
sdk default java 8.0.372-amzn
It would be great to automatically switch Java version when cd-ing into the project folder. This behavior is supported, but disabled by default. To enable it, run the below command to open the configuration file.
sdk config
Now set the value of config key sdkman_auto_env
to true
. Now automatic version management is
enabled. For any project, just make sure there is a .sdkmanrc
file with details on which Java
version to use.
java=17.0.7-amzn
Now the Java version is switched automatically, as soon as I cd in to the directory, but is restored to default if we move out.
SDKMAN! works for other tools as well.
sdk install maven
sdk install gradle
sdk install jmeter