How to get sdkman to default to latest point release of a java major version

548 Views Asked by At

I am using sdkman on my machine to manage Java. when I run sdk list java I see all the patch point releases. For example I see Corretto version 21 with id 21-amzn and Corretto version 21.0.1 with id 21.0.1-amzn I would like to be able to say something like "sdkman please use the latest Java 21 from Amazon Corretto" with the expectation that sdkman can keep updating to the latest patch release.

When I run sdk upgrade java it prints out java is up-to-date but when I run sdk list java I see the output below clearly there is a newer patch release of corretto 21.0.1 but upgrade seems to treat 21 and 21.0.1 as totally different versions.

Question: Is there some way to configure sdkman commands to always use the latest stable release of a major version of java from a specific distro?

================================================================================
Available Java Versions for macOS ARM 64bit
================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 Corretto      |     | 21           | amzn    | installed  | 21-amzn             
               |     | 21.0.1       | amzn    |            | 21.0.1-amzn         
               |     | 20.0.2       | amzn    |            | 20.0.2-amzn         
               |     | 20.0.1       | amzn    |            | 20.0.1-amzn         
               |     | 17.0.9       | amzn    |            | 17.0.9-amzn         
               |     | 17.0.8       | amzn    |            | 17.0.8-amzn         
               |     | 17.0.7       | amzn    |            | 17.0.7-amzn         
               |     | 11.0.21      | amzn    |            | 11.0.21-amzn        
               |     | 11.0.20      | amzn    |            | 11.0.20-amzn        
               |     | 11.0.19      | amzn    |            | 11.0.19-amzn        
               |     | 8.0.392      | amzn    |            | 8.0.392-amzn        
               |     | 8.0.382      | amzn    |            | 8.0.382-amzn        
               |     | 8.0.372      | amzn    |            | 8.0.372-amzn  
2

There are 2 best solutions below

0
On

Preface:

Just from their official docs: https://sdkman.io/usage#upgrade

Installing the latest stable version of XXX:

Install the latest stable version of your SDK of choice (say, Java JDK) by running the following command:

$ sdk install java

Workaround:

Create a bash script which

  1. Gets the latest version as text
  2. Creates the appropriate SDK command
  3. Executes the command
0
On

You can use the below command to install a specific distribution from a vendor:

sdk install java <<Identifier>>

where, Identifier = Version-Dist

For example: If you want to install and use the 21.0.1-amzn of JDK, then execute this command:

sdk install java 21.0.1-amzn 

where,

  • Version=21.0.1
  • Dist=amzn
  • Identifier=Version-Dist=21.0.1-amzn

When you run the command sdkman list java, it shows all the stable JDK distributions that were released from all the vendors in the order of latest to oldest that you can select.

Note: You are correct. After downloading 21.0.1-amzn and 21-amzn, I found out that both the distributions point to same implementor version of Corretto-21.0.1.12.1 after reading the README files from both distributions.

enter image description here

I guess the 21-amzn just a marker for 21.0.1-amzn to say that it's a "final" distribution unless a newer distribution is available from Corretto JDK 21..

So, if you are install any of them, you are actually installing Corretto-21.0.1.12.1 on the system.

See the SDKMAN JDK Distributions docs here for reference.