Skip to content

Java Runtime incorrect, when using gradle toolchains #2804

Open

Description

@levno-710

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

Activity

  1. jdneo commented on Nov 17, 2022

    @jdneo
    Collaborator

    Looks like an issue related with eclipse-buildship/buildship#1039

  2. cypher256 commented on Apr 9, 2024

    @cypher256

    Currently, toolchain can be used successfully in Eclipse by specifying it as an argument.
    Eclipse: Preference > Gradle > Advanced Options > Program Arguments

    -Porg.gradle.java.installations.paths=C:/java/11,C:/java/17,C:/java/21
    

    However, it does not work even if I specify it as an argument to VSCode.

    "java.import.gradle.arguments": "-Porg.gradle.java.installations.paths=C:\\java\\11,C:\\java\\17,C:\\java\\21",
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions