Manage multiple Java SDKs with SDKMAN! with ease
SDKMAN! is a convenient tool for managing parallel versions of multiple Software Development Kits. The tool is especially useful for Java developers as it supports SDKs for the JVM such as Java, Groovy, Scala, Kotlin and Ceylon. Gradle, Maven, Spring Boot and many others are also supported.
SDKMAN! is supported for all major operating systems including Windows, although it is easiest to be installed on all Unix based systems.
On macOS, open a terminal and run:
1 |
Once downloaded restart the terminal session or run:
1 | source "$HOME/.sdkman/bin/sdkman-init.sh" |
Tip: I am using iTerm2 terminal as default. Read about tools I use on macOS in this blog post: macOS: Essential tools for (Java) developer
Once installed, SDKMAN! provides a convenient sdk
command for managing SDKs, called Candidates. To list all available Candidates use sdk list
command.
Manage Java Versions
What I like most about SDKMAN! is that managing different Java versions in your operating system is a breeze. You can list, install, uninstall and set selected Java version as default with basic commands.
- To list available Java versions run:
sdk list java
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | $ sdk list java ================================================================================ Available Java Versions ================================================================================ Vendor | Use | Version | Dist | Status | Identifier -------------------------------------------------------------------------------- AdoptOpenJDK | | 13.0 . 1 .j9 | adpt | | 13.0 . 1 .j9-adpt | | 13.0 . 1 .hs | adpt | | 13.0 . 1 .hs-adpt GraalVM | | 19.3 . 0 .r11 | grl | | 19.3 . 0 .r11-grl | | 19.3 . 0 .r8 | grl | | 19.3 . 0 .r8-grl | | 19.3 . 0.2 .r11 | grl | | 19.3 . 0.2 .r11-grl Java.net | | 15 .ea. 2 | open | | 15 .ea. 2 -open | | 14 .ea. 28 | open | | 14 .ea. 28 -open | >>> | 13.0 . 1 | open | installed | 13.0 . 1 -open | | 12.0 . 2 | open | installed | 12.0 . 2 -open | | 11.0 . 2 | open | | 11.0 . 2 -open | | 10.0 . 2 | open | | 10.0 . 2 -open | | 9.0 . 4 | open | | 9.0 . 4 -open ================================================================================ Use the Identifier for installation: $ sdk install java 11.0 . 3 .hs-adpt ================================================================================ |
- To install given version use the Identifier:
sdk install java 12.0.2-open
The binaries of the installed Java versions can be found in the home SDKMAN! directory which defaults to ~/.sdkman/candidates/java
.
1 2 3 4 | $ ls -al ~/.sdkman/candidates/java/ drwxr-xr-x 9 rafal.borowiec staff 288 Jan 4 00 : 33 12.0 . 2 -open drwxr-xr-x 9 rafal.borowiec staff 288 Oct 6 14 : 05 13.0 . 1 -open lrwxr-xr-x 1 rafal.borowiec staff 57 Jan 4 00 : 20 current -> /Users/rafal.borowiec/.sdkman/candidates/java/ 13.0 . 1 -open |
This can be useful if you want to use multiple versions in your projects in IntelliJ, for example.
- To set given version as default run:
sdk default java 12.0.2-open
:
We can quickly verify how how easy is to change the version with sdk default
command:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 | $ java -version openjdk version "13.0.1" 2019 - 10 - 15 OpenJDK Runtime Environment (build 13.0 . 1 + 9 ) OpenJDK 64 -Bit Server VM (build 13.0 . 1 + 9 , mixed mode, sharing) $ ls -al ~/.sdkman/candidates/java/ drwxr-xr-x 9 rafal.borowiec staff 288 Jan 4 00 : 33 12.0 . 2 -open drwxr-xr-x 9 rafal.borowiec staff 288 Oct 6 14 : 05 13.0 . 1 -open lrwxr-xr-x 1 rafal.borowiec staff 57 Jan 4 00 : 20 current -> /Users/rafal.borowiec/.sdkman/candidates/java/ 13.0 . 1 -open $ sdk default java 12.0 . 2 -open Default java version set to 12.0 . 2 -open $ java -version openjdk version "12.0.2" 2019 - 07 - 16 OpenJDK Runtime Environment (build 12.0 . 2 + 10 ) OpenJDK 64 -Bit Server VM (build 12.0 . 2 + 10 , mixed mode, sharing) $ ls -al ~/.sdkman/candidates/java/ drwxr-xr-x 9 rafal.borowiec staff 288 Jan 4 00 : 33 12.0 . 2 -open drwxr-xr-x 9 rafal.borowiec staff 288 Oct 6 14 : 05 13.0 . 1 -open lrwxr-xr-x 1 rafal.borowiec staff 57 Jan 5 11 : 49 current -> /Users/rafal.borowiec/.sdkman/candidates/java/ 12.0 . 2 -open |
- To use given version in the current terminal session run:
sdk use java 12.0.2-open
Install Maven and Gradle
Maven and Gradle are open-source tools for automating the process of building applications and managing their dependencies. Both tools can be managed with SDKMAN!.
- Install Maven with the following command:
1 2 3 4 5 6 7 8 | $ sdk install maven Downloading: maven 3.6 . 3 In progress... 100.0 % Installing: maven 3.6 . 3 Done installing! Setting maven 3.6 . 3 as default . |
- Install Gradle with the following command:
1 2 3 4 5 6 7 8 | $ sdk install gradle Downloading: gradle 6.0 . 1 In progress... 100.0 % Installing: gradle 6.0 . 1 Done installing! Setting gradle 6.0 . 1 as default . |
If you need multiple versions of Gradle or Maven you can install them by providing desired version with sdk install maven 3.6.1
and then switch between them using sdk set
or sdk default
commands.
Install Spring Boot CLI
The Spring Boot CLI is a command line tool that you can use if you want to quickly develop a Spring application.
You can check available Spring Boot versions with sdk list springboot
command:
1 2 3 4 5 6 7 | $ sdk list springboot ================================================================================ Available Springboot Versions ================================================================================ 2.2 . 2 .RELEASE 2.0 . 1 .RELEASE 1.5 . 1 .RELEASE 1.2 . 3 .RELEASE 2.2 . 1 .RELEASE 2.0 . 0 .RELEASE 1.4 . 7 .RELEASE 1.2 . 2 .RELEASE 2.2 . 0 .RELEASE 1.5 . 22 .RELEASE 1.4 . 6 .RELEASE 1.2 . 1 .RELEASE |
Install default version by running sdk install springboot
.
Once installed, spring
command will be available:
1 2 3 | $ spring usage: spring [--help] [--version] <command> [<args>] |
You can now bootstrap a new Spring Boot project by running:
1 2 3 | $ spring init --build=gradle --java-version= 12 --dependencies=web --packaging=jar my-app.zip Using service at https: //start.spring.io Content saved to 'my-app.zip' |
Unpack the zip and from within the application directory run:
1 2 3 | gradle bootRun Tomcat started on port(s): 8080 (http) with context path '' 2020 - 01 - 04 12 : 36 : 59.704 INFO 57156 --- [ main] com.example.myapp.DemoApplication : Started DemoApplication in 1.251 seconds (JVM running for 1.485 ) |
Note: the above command used global Gradle distribution you installed with SDKMAN!, you can run it also with local Gradle installation by invoking ./gradlew
command.
Once the application has started, check if it responds to your requests:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 | $ http localhost: 8080 HTTP/ 1.1 404 Connection: keep-alive Content-Type: application/json Date: Sun, 05 Jan 2020 11 : 38 : 08 GMT Keep-Alive: timeout= 60 Transfer-Encoding: chunked Vary: Origin Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers { "error" : "Not Found" , "message" : "No message available" , "path" : "/" , "status" : 404 , "timestamp" : "2020-01-05T11:38:08.041+0000" } |
Tip: I am using httpie client, not cURL. Read about tools I use on macOS in this blog post: macOS: Essential tools for (Java) developer
Links
Do you use SDKMAN!? When do you find it useful? Share your thougths in the comments.
Published on Java Code Geeks with permission by Rafal Borowiec, partner at our JCG program. See the original article here: Manage multiple Java SDKs with SDKMAN! with ease Opinions expressed by Java Code Geeks contributors are their own. |
Very useful, except for some tools on macOS that expect Java in the default location.
Hi…
I’m Elena gillbert.Search Results
Featured snippet from the web
Manage multiple Java SDKs with SDKMAN! with ease. SDKMAN! is a convenient tool for managing parallel versions of multiple Software Development Kits. The tool is especially useful for Java developers as it supports SDKs for the JVM such as Java, Groovy, Scala, Kotlin and Ceylon.