redhat-developer / redhat-developer/vscode-java

Java Runtime incorrect, when using gradle toolchains

Open
#2,804 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Gradle runtime
Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

I am using the following build.gradle file:

plugins {
    // Apply the java-library plugin for API and implementation separation.
    id 'java-library'
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
}

dependencies {
    // Use JUnit test framework.
    testImplementation 'junit:junit:4.13'

    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:29.0-jre'

    // Java Parser and Code Generator
    implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.24.7'
}

It uses the Java 1.17 toolchain, however in the Configure Java Runtime Tab, it shows Java Version 12:
Capture

When I try to use newer Java features, it shows the following Error:
The Java feature 'Text Blocks' is only available with source level 15 and above

Environment
  • Operating System: Windows 10
  • JDK version: 1.17
  • Visual Studio Code version:
  • Java extension version: 1.12.0
  • Gradle version: 7.0.0
Steps To Reproduce

Sample Project: java-rewriter.zip

  1. open lib/src/test/java/dev/levno/javarewriter/LibraryTest.java in vscode
  2. Error is shown
Current Result

Error is displayed in File

Expected Result

No Error should be displayed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sample project's build.gradle and lib/src/test/java/dev/levno/javarewriter/LibraryTest.java, then reproduce the diagnostic in VS Code and inspect the Configure Java Runtime tab. Done means the project using the Java 17 Gradle toolchain no longer reports the text-block source-level error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.