Thursday, October 14, 2021

Managing Multiple Sotware Development Kits Using SDK Man!


Background

I once wrote a Java Shell Script that switches among the Java versions on my machine. The nice thing is that it worked well. Even shared it across the dev team and it worked like a charm. The pain come when I wanted to do the same with other tools ... i.e Maven; Kotlin; Kscript; Groovy & Gradle to name a few.

This would require regular maintenance on the script which would at some point require more and more time, while one needs to take care of real software development matters. I spend a lot of time on Unix based OS like working on Mac OS and you find that the organisation is hosting on Linux OS so I needed something that could work for both, something more flexible.

After some research I then learned about SDK Man! Which simply means Software Development Kit Manager.


 

What is SDK Man?

As hinted above this is Software Development Kit Manager. This tool helps with management of various tools in a simpler, cleaner and central place. One can manage all this in a parallel manner. As a company you will not have to worry about setting a standard from scratch. Think of standards like paths and directories. One developer saves their maven in folder x/y/z and the other one is /a/b/c ... now this could be hard to maintain and support. SDK Man will sort out all this in one directory out of the box.

 
 

Why Was SDK Man Introduced?

As a developer you deal with a lot of versions of one tool or you deal with various tools at once. Switching versions of the same tool and getting up and running with a different tool take up a lot of time and SDK Man was made to relieve you from all that effort. Things like setting up your JAVA_HOME path or GROOVY_HOME path can be quite an exercise. At times you find that one projects uses Java 8 and another one uses Java 14 and switching between the two requires a little bit more work. You either write a script to do that for you or you work with some like jEnv ( Java Environment ) , but as the name suggests, this is only for Java. Imagine if you could do this for other SDKs!


 
 

Getting Started.

For Windows OS can use Cygwin then for Unix platforms to install SDK Man is easy. For Windows OS I would rather use something else instead of SDK Man so tune into my next article coming soon! So start up your terminal to get started. Type the command : 


# Command to download SDK Man
curl -s "https://get.sdkman.io" | bash


SDK Man Installation Results

 

The screenshot above gives you an idea of how things should be. And that's simple as that. Take note of the dependencies that SDK man is looking for before installing.

We can run a few checks to see if SDK Man is really installed. Let's check the SDK Man version by running the command :


# Checking SDK Man Version
sdk version


SDK Man Version Check


The Actual Works

So now that SDK Man has been installed let check out how it works. We will go through a few short cases. 

 

  • We want to see all supported candidates in SDK Man to see what is offers.

    # Checking All Supported Candidates aka SDKs
    sdk list


    SDK Man Supported Candidates or SDKs


  • So now you have spotted something you want to install and want to check the versions first before installation. In my case I will pick maven. So let's see what versions are there :

    # Checking All Candidate Versions ( Maven in this case )
    sdk list maven


Supported Maven Versions On SDK Man

SDK Man is giving us a guide on which maven is installed on my machine. It's also showing what we wanted to see, which is all version supported on SDK Man. We also get to see which maven verion is in use on my mahine. So this is a good guide when working with a tool like SDK Man and multiple version of the same tool, in this case maven.


  • I have now decided that I want to install maven 3.8.2 and I install it as follows:

    # Checking All Candidate Versions ( Maven in this case )
    sdk install maven 3.8.2



    SDK Man, Maven Installation


Yes, it's correct that SDK Man asks you if you want to make the version you have just installed, the main one. So SDK Man has spotted that there are more than one versions of Maven installed and is asking if I want use the one I have just installed as the main one. I will chose "No" so that we can do that later.

 

  • Let's see all the maven sdks I have SDK Man, Maven Installation
    # List Maven Versions
    sdk list maven



    SDK Man, Maven List

We can see all the installed maven SDKs on the machine from the image above. I am using maven 3.8.1 on the machine and I have also installed 3.8.2. So let's see how to set a new version for the terminal session only or on the entire machine permanently. 


  • Setting maven in the current active terminal session. So in other ways we are setting it, temporarily :

    # Temporarily set maven
    sdk use maven 3.8.2


    SDK Use Maven ${Version}


  • Setting maven permanently, so this will not be in the current termianl session only :

    # Permanently set maven
    sdk default maven 3.8.2


SDK Default Maven ${Version}

 

  • So you want to be explicit when checking the current maven that's beng used :

    # Check current version in use
    sdk current maven


    SDK Current Maven

  • Now you decide that you are no longer using the older version of Maven so you want to remove it :

    # Check current version in use
    sdk uninstall maven 3.8.1



    SDK Uninstall Maven

Well done to you, now you understand SDK Man! You are wondering how you can point your IDE to these SDKs because so far you have just been using the terminal. So close up this article with that. So if you go to your home directory /Users/${yourname}/.sdkman aka ${HOME}/.sdkman, then you will find the SDK Man folders in there. So you want to use a specific JDK for your Java project, then look into the "candidates" folder because that's where all the SDKs are.


SDKs Home


So you can choose the version that you want, as shown in the image below.


IntelliJ IDEA IDE Using SDK Man Java


I hope you have enjoyed this article and this will help you. Leave comments in the section below and let me know your thoughts. Thanks!



No comments:

Post a Comment