images icon indicating copy to clipboard operation
images copied to clipboard

Java images are confusing JDK installations

Open brunoborges opened this issue 1 year ago • 7 comments

The Java images contain a JDK installed manually (through the image build in this repo) along with JDK(s) installed through the Java feature (SDKMan!).

This is creating confusion and even some conflicts when the user needs to change the JDK.

brunoborges avatar Jul 14 '24 07:07 brunoborges

@gauravsaini04 Can you help investigate this issue? Thanks!

samruddhikhandale avatar Jul 17 '24 23:07 samruddhikhandale

Hi @samruddhikhandale , https://github.com/devcontainers/features/blob/main/src/java/install.sh#L208 here the requested_version is none which we are passing from the image devcontainer.json as below: https://github.com/devcontainers/images/blob/main/src/java/.devcontainer/devcontainer.json#L7-L9

So when the version is none , feature is not installing any jdk by SDKMan. What else we have to analyse here ?

prathameshzarkar9 avatar Aug 01 '24 10:08 prathameshzarkar9

@prathameshzarkar9 assuming that I open a Java project using the default Java devcontainer, what is the correct way to get the right JDK for said project? Consider that the JDK installed is X, but the project requires JDK Y.

brunoborges avatar Aug 01 '24 23:08 brunoborges

Hi @brunoborges , to install the right jdk in default java container using the java feature in devcontainer.json is as follows:

"ghcr.io/devcontainers/features/java:1": {
            "version": "Y"
        },

Here, the Y version is the version required for the project to install the right JDK

prathameshzarkar9 avatar Aug 06 '24 09:08 prathameshzarkar9

If I am already inside a dev container that was loaded with the default Java devcontainer, the easiest way for me as a Java developer to use a different JDK is to install another version with sdkman, especially because sdkman is available in the devcontainer in the first place.

@prathameshzarkar9 I'm afraid your suggestion is not idiomatic and requires one to make changes (or a brand new configuration) of devcontainer metadata in a repo the user may not even have write permission (thus, requiring a fork).

brunoborges avatar Aug 08 '24 16:08 brunoborges

Due to historical reasons, we have always installed Microsoft's OpenJDK in the image, and the Java feature installs sdkman. We understand the confusion this might have caused. However, changing the behavior now would be a breaking change, as this setup has been deployed in this way for many years, and users might depend on either JDK.

We appreciate your feedback. Let's keep this issue open until we receive more similar user feedback. Thanks!

samruddhikhandale avatar Aug 27 '24 23:08 samruddhikhandale

When I install only gradle with Java Image and start the container, gradle use /usr/local/sdkman/candidates/java/current even though I have not installed Java using sdkman.This is very inconvenient.

noguchi-taketo avatar Apr 16 '25 01:04 noguchi-taketo