Passing the `release` option to the compiler [message #1857536] |
Tue, 14 February 2023 14:11 |
Simon Cockx![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=simon%40sikanda.be) 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?
|
|
|
Powered by
FUDForum. Page generated in 0.02842 seconds