Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK 8 not being auto-selected as Project-Level SDK on Jetbrains IDE #15114

Closed
fcamblor opened this issue Dec 1, 2022 · 9 comments
Closed

JDK 8 not being auto-selected as Project-Level SDK on Jetbrains IDE #15114

fcamblor opened this issue Dec 1, 2022 · 9 comments
Assignees
Labels

Comments

@fcamblor
Copy link

fcamblor commented Dec 1, 2022

Bug description

As discussed on Discord I'm encountering problem while trying to pre-select something different than te default Project-Level SDK (JDK 11 on Intellij 2022.2.4)

Got help from @felladrin who suggested to create this issue, telling that the problem may be located around here

Steps to reproduce

You can start a gitpod instance with JDK pre-installed :

FROM gitpod/workspace-full

USER gitpod

RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \
    sdk install java 8.0.352-zulu && \
    sdk default java 8.0.352-zulu"

ENV IDEA_JDK /home/gitpod/.sdkman/candidates/java/current
ENV JAVA_HOME /home/gitpod/.sdkman/candidates/java/current

But Project-level JDK remains with pre-bundled JDK 11 :
image
image

Workspace affected

No response

Expected behavior

I would expect that Project-Level JDK should be set to globally-configured JDK (in case above, JDK 8)

Example repository

FROM gitpod/workspace-full

USER gitpod

RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \
    sdk install java 8.0.352-zulu && \
    sdk default java 8.0.352-zulu"

ENV IDEA_JDK /home/gitpod/.sdkman/candidates/java/current
ENV JAVA_HOME /home/gitpod/.sdkman/candidates/java/current

Anything else?

It could be related to a Jetbrains issue here regarding JDK Detector.

@loujaybee
Copy link
Member

loujaybee commented Dec 5, 2022

When we resolve the issue, we should also update docs on how to override / set the default version for a project.

Including things like order of precedence and how to test whether your changes have applied to the workspace.

https://www.gitpod.io/docs/introduction/languages/java#updating-java-maven--gradle
https://www.gitpod.io/docs/references/ides-and-editors/intellij

@akosyakov
Copy link
Member

@fcamblor IntelliJ detects JDK version form maven or gradle configuration and try to find the compatible one, i.e. if pom.xml has java 11 set then even if default JDK is 8, IntelliJ will pick the highest closest (i.e. compatible).

Could you check what your project has specified in source/target level in pom.xml or gradle.build?

@fcamblor
Copy link
Author

Hello @akosyakov,

I'm not using maven nor gradle in my case, this is a Scala project which relies on sbt.
I'm not an expert on this field, but I don't see where the Java version is specified in the sbt build file (I can only see that a Scala version is enforced, nothing more)

@akosyakov
Copy link
Member

We reverted the custom JDK detection logic to use one from IntelliJ itself, but it behaves the same way. Here is an issue in the upstream: https://youtrack.jetbrains.com/issue/GTW-2758/IntelliJ-selects-Java-17-when-pom.xml-targets-Java-11-without-.idea-folder

@andreafalzetti
Copy link
Contributor

@fcamblor our workspace-full image comes with both Java 11 and Java 17. We also have dedicated Java images for 11 and 17, but not one for 8.

I would recommend removing the versions you don't need and by doing that, IntelliJ will pick up the right JDK.

FROM gitpod/workspace-full:2022-12-15-12-38-23

USER gitpod

RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \
    sdk uninstall java 17.0.5.fx-zulu && \
    sdk uninstall java 11.0.17.fx-zulu && \
    sdk install java 8.0.352-zulu && \
    sdk default java 8.0.352-zulu"

Note: I've pinned the image to the most recent tag 2022-12-15-12-38-23 this will prevent your image to change in case we update and in the future install additional versions of Java

Screenshot 2022-12-20 at 11 21 25

@felladrin
Copy link
Contributor

@fcamblor, did you have a chance to try the solution mentioned above by Andrea?

@fcamblor
Copy link
Author

Sorry, it got out of my radar.

I've just launched a re-build of my particular Scala workspace to check it.
I will keep you posted (it can take a few dozen of minutes to complete, as it seems my docker build cache as disappeared and I'm going to need to download the whole internet again to build my SBT dependencies cache :-))

@fcamblor
Copy link
Author

It took some time, but it doesn't look like uninstalling sdkman's jdk 11 & 17 changed anything for my setup, except that the default project SDK is not found at project startup :
Cursor_and_Project_Structure_and_cfp-devoxx

Cursor_and_Project_Structure

I used latest workspace-full image available (gitpod/workspace-full:2023-01-10-16-35-53)

@fcamblor
Copy link
Author

fcamblor commented Jan 13, 2023

Forget, this is my bad, I just discovered that during my test above, I had a .gitpod/jetbrains/options/jdk.table.xml which was targetting old JDK 11/17

I updated the file (removed uninstalled JDK references, keeping only my JDK 8 in it) and this time, it worked fine ! :-)

Cursor_and_Project_Structure

Thanks everyone for the help, much appreciated !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants