vscode-java
vscode-java copied to clipboard
OpenJDK 17 --enable-preview breaks error reporting
I wanted to use the new switch syntax that's still a preview in 17. I changed my maven pom.xml to have
<plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <compilerArgs>--enable-preview</compilerArgs> </configuration> </plugin>
In the Syntax Server output window it has,
[Error - 1:49:59 PM] Connection to server got closed. Server will not be restarted.
It stops highlighting compiler errors/warnings in the editor. Removing the --enable-preview stuff from pom.xml solves the problem, but then I lose the error reporting.
It breaks regardless of whether or not my code uses any preview features.
Environment
- Operating System: Ubuntu 20.04
- JDK version: openjdk version "17.0.3" 2022-04-19
- Visual Studio Code version: 1.69.2
- Java extension version:
Steps To Reproduce
- [step 1]
- [step 2]
[Please attach a sample project reproducing the error] Please attach logs
Current Result
Expected Result
Additional Informations
Due to a limitation in the underlying ECJ compiler, preview fearures are only supported with the latest Java release, i.e Java 18 as of today. See https://github.com/redhat-developer/vscode-java/wiki/Enabling-Java-preview-features
One suggestion is to use a custom Maven profile that would set the Java version to 18 when running inside vscode-java or Eclipse. For instance:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>${java.version}</release>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile><!--Automatically activates when running inside m2e (i.e vscode-java/Eclipse)-->
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<properties>
<java.version>18</java.version>
</properties>
</profile>
</profiles>
</project>
Is there no way for it to detect that and pop up an error message instead of failing silently?