Open straywarrior opened 1 year ago
The language server executes Maven in the same JVM it's started with, so basically, the ${java.home}
property is resolved with JDK17 in net.openhft:compiler:2.2.0:
<dependency>
<groupId>com.sun.java</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
Does your project still compile if you exclude tools.jar with:
<dependency>
<groupId>net.openhft</groupId>
<artifactId>lang</artifactId>
<version>6.6.11</version>
<exclusions>
<exclusion>
<groupId>com.sun.java</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>
?
@fbricon Thanks for reply. The answer is yes. If I exclude tools.jar, it can be compiled without error both by Maven and the Language Server. And it is why I can locate the problem.
In the real situation, com.sun.java.tools
is a really "deep" dependency that is included indirectly and I'm not sure whether I can exclude it safely.
Is it possible to change the environment of Maven in the language server?
I have a Maven project that uses JDK 1.8. If I add a dependency, such as
net.openhft.lang
, containingcom.sun.java.tools
(without specifying the version) to this project, the language server will generate an error "Missing artifact com.sun.java:tools:jar:17.0.6", indicating that it cannot compile. However, if I compile the project directly usingmvn package
, there are no errors. I usemvn dependency:tree
to find that the version ofcom.sun.java.tools
is just same as my JDK version installed and specified in the system (1.8.0_151). It seems that the compilation behavior of the language server is different from directly using Maven, as it tries to look for version 17.0.6 (the JDK version embedded in the language server), instead of using version 1.8 in my system.Environment
Steps To Reproduce
sample project: https://github.com/straywarrior/issue_samples/tree/main/vscode-java/maven-test-project logs:
Current Result
Language server returns error: Missing artifact com.sun.java:tools:jar:17.0.6
Expected Result
No error should occur.
Additional Informations
mvn dependency:tree
output:VSCode settings.json