@DisabledForJreRange and @EnabledForJreRange using source target rather what java version being used
I have tests with:
@DisabledForJreRange(min = JRE.JAVA_8, max = JRE.JAVA_8, disabledReason = "JSH is not supported on Java 8")
and even though I'm running with Java 17 all tests are ignored in vscode but run when running with gradle.
Only way I can get them to be included is to change:
sourceCompatibility = '8'
targetCompatibility = '8'
to
sourceCompatibility = '17'
targetCompatibility = '17'
but it is not consistent.
In any case vscode-java testrunner auto ignore tests that shouldn't be ignored compared to gradle command line.
Hi @maxandersen, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
Here are some ways to force VS Code to pick up your real Java 17 runtime instead of using the source/target values:
• Configure Gradle’s JVM in VS Code settings so import (and the Test Runner) use JDK 17:
// settings.json
"java.import.gradle.java.home": "/path/to/jdk-17"
This makes VS Code launch Gradle (and thus the tests) with your Java 17 installation.
• Use java.configuration.runtimes to map the “JavaSE-17” runtime to your JDK 17:
"java.configuration.runtimes": [
{
"name": "JavaSE-17",
"path": "/path/to/jdk-17"
}
]
Then run the Java: Configure Java Runtime command and ensure your project uses the “JavaSE-17” entry.
• If you’re on Gradle toolchains, also add to build.gradle:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
and make sure your VS Code Java Extension is up-to-date (≥1.22) so it supports Gradle toolchains properly.
High-confidence reference:
• “Java Runtime incorrect, when using gradle toolchains”
https://github.com/redhat-developer/vscode-java/issues/2804
Extension shows wrong Java version (12) despite toolchain=17 – same root cause of wrong JRE detection.
Other references with low confidence
• “java has been set to 11 as default”
https://github.com/redhat-developer/vscode-java/issues/3136
VS Code defaults to Java 11 for import even when sourceCompatibility=17 – suggests configuring java.configuration.runtimes.
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!