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

java has been set to 11 as default #3136

Open
fssrepository opened this issue Jun 4, 2023 · 12 comments
Open

java has been set to 11 as default #3136

fssrepository opened this issue Jun 4, 2023 · 12 comments

Comments

@fssrepository
Copy link

Environment
  • Operating System: Ubuntu 20.04
  • JDK version: 8/11/17
  • Visual Studio Code version: 1.78.2
  • Java extension version: 0.25.11 (Extension pack for java)
Steps To Reproduce
  1. install java 17 (upgrade alternative to it)
  2. go to https://start.spring.io/ -> Gradle Groovy, Java, 3.1.0, jar, 17 and generate
  3. open it in vscode
Current Result

org.springframework.boot.gradle 3.1.0 can't be resolved,
(Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs))
the language support plugin is uses java 11 as default to import, even if the seourceCompatibility has been set and
the gradle.properties org.gradle.java.home=/usr/lib/jvm/java-17-openjdk-amd64 on project level has been set (root folder)

The only way was to resolve is "java.import.gradle.java.home": "/usr/lib/jvm/java-1.17.0-openjdk-amd64", which is painful to figure out, intellij is behaving similarly (Gradle JVM needs to be set -> hasn't tested the gradle.properties in this case)

Expected Result

I would have expected:
a) whatever the JAVA_HOME sais, and the java.import.gradle.java.home is not set,
it's using the JAVA_HOME for gradle import also. (command line is using it)
b) if gradle.properties has been set is picking up java folder from there

It is the behavior being described in the official gradle manual.

Additional Informations

I'm using gradle for java plugin also.
The difference between intellij and vscode was, that the Gradle JVM had a default value. (randomly selected one)

After several attempt and screw up, cleaning up language server (ctrl+shift+p -> relevant command) didn't help, just removing all the workspace folder,
remove the project from workspace and restart and add back the project.

In this case java classes has been identified as non-project files!

@fssrepository
Copy link
Author

cross attached:

microsoft/vscode-gradle#1340

@snjeza
Copy link
Contributor

snjeza commented Jun 4, 2023

@fssrepository I can't reproduce the issue.
Could you run the following commands:

$ echo $JAVA_HOME 
$ java -version

@fssrepository
Copy link
Author

openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Ubuntu-0ubuntu120.04, mixed mode, sharing)

@snjeza
Copy link
Contributor

snjeza commented Jun 4, 2023

You should set JAVA_HOME.
You have to check if it is /usr/lib/jvm/java-1.17.0-openjdk-amd64 or /usr/lib/jvm/java-17-openjdk-amd64

$ which java

@fssrepository
Copy link
Author

fssrepository commented Jun 4, 2023

JAVA_HOME has been automatically set, while java 17 installer was running.

JAVA_HOME => /usr/lib/jvm/java-17-openjdk-amd64

The problem, as i said is plugin one.
"./gradlew build" from terminal was perfectly fine, without any configuration.
It was reacting also to gradle.properties. (i set to java 11, and it failed right away with the error above)

The plugin either the gradle for java, or the language support is hard coding java 11, because it was the first version from which these plugins have got support. I had to upgrade to java 11 from java 8, as it was not working. (a year ago)

It's causing issues only on gradle import, but building the source code to java 17. The plugin itself is printing out java 17, and screwing up at gradle import.

plugins {
id 'java'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.raxim'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

when id java is running picking up the 17 source compatibility (using java 17), but the
id 'org.springframework.boot' version '3.1.0' is trying to make a gradle import on java 11.

@fssrepository
Copy link
Author

fssrepository commented Jun 4, 2023

  • What went wrong:
    A problem occurred configuring root project 'myscoutee'.

Could not resolve all files for configuration ':classpath'.
Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.0.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.0
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.1.1' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.0 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.0 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')

pls. don't confuse that i have upgraded the 8.1.1 lately, same problem...It happens inside the vscode, but not from command prompt (I have also multi jdk, 17 is default, but i have 8 and 11 installed also)

@fssrepository
Copy link
Author

fssrepository commented Jun 4, 2023

/usr/lib/jvm/java-1.17.0-openjdk-amd64 or /usr/lib/jvm/java-17-openjdk-amd64 does not make that much difference, the 1.17 is a simplink to the 17, which is a simplink to an openjdk-17..."really nice stuff". however installer set up the JAVA_HOME not me.

@snjeza
Copy link
Contributor

snjeza commented Jun 4, 2023

Could you try

$ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
$ export PATH=${JAVA_HOME}/bin:$PATH
$ cd <your_project_root>
$ code .

@shijo-keyvalue
Copy link

I am also facing the same problem.

@hugo-marello
Copy link

Same problem here, the plugin doesn't go well with jdk 17

@fssrepository
Copy link
Author

fssrepository commented Jul 27, 2023 via email

@cypher256
Copy link

cypher256 commented May 21, 2024

I would have expected:
a) whatever the JAVA_HOME sais, and the java.import.gradle.java.home is not set,
it's using the JAVA_HOME for gradle import also. (command line is using it)

The exact Precedence is below.

  1. settings.json java.import.gradle.java.home
  2. settings.json java.jdt.ls.java.home (Default is Red Hat embedded JRE)
  3. settings.json java.home (deprecated)
  4. env var JAVA_HOME
  5. env var PATH

The design problem is that the Gradle extension references java.jdt.ls.java.home for the Red Hat extension language server. This is counter-intuitive.

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

No branches or pull requests

5 participants