Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Passing the `release` option to the compiler
Passing the `release` option to the compiler [message #1857536] Tue, 14 February 2023 14:11
Simon Cockx is currently offline Simon CockxFriend
Messages: 69
Registered: October 2021
Member
Original post on the Xtext forum: https://www.eclipse.org/forums/index.php/t/1112496/


Based on a DSL, we are generating Java code that should be Java 8 compatible. To test this, we use the `org.eclipse.jdt.internal.compiler.Compiler` class in our unit tests with compiler options `sourceLevel`, `complianceLevel` and `targetJDK` set to Java 8.

However, I've just ran into an issue where I've accidentally used a Java 9 feature, but our unit tests didn't fail, causing me to believe it was Java 8 compatible and releasing, only having to find out later that projects depending on our DSL where failing to build.

The feature that I used is the static method `List::of`, which doesn't exist until Java 9.

In short, what I've found out by digging into the source code:
- The flag that I actually need instead is the `-release` flag, which would also override the `-bootclasspath` to be Java 8 compatible.
- The class used to represent compiler options, i.e., `org.eclipse.jdt.internal.compiler.impl.CompilerOptions`, doesn't seem to support the `-release` flag. A snippet from `CompilerOptions::getMap`:

optionsMap.put(OPTION_Compliance, versionFromJdkLevel(this.complianceLevel));
optionsMap.put(OPTION_Release, DISABLED); // ----------------------------------------> see this line
optionsMap.put(OPTION_Source, versionFromJdkLevel(this.sourceLevel));
optionsMap.put(OPTION_TargetPlatform, versionFromJdkLevel(this.targetJDK));



In essence, this means I'm only able to unit test that we're not using Java 9+ language features, but I'm not able to test that we're not using Java 9+ standard library features.

Is there a way to fix this? Or does the compiler just not have support for the `-release` flag?
Previous Topic:2022-12 Eclipse Showing @param as misspelled
Next Topic:The extension took too long to return from the computeCompletionProposals()' operation.
Goto Forum:
  


Current Time: Sun Jan 26 13:20:20 GMT 2025

Powered by FUDForum. Page generated in 0.02842 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top