redhat-developer / redhat-developer/vscode-java

dependency with com.sun.java.tools causes building error

未关闭
#3,047 4 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
TypeScript
星标
2.3k
派生
546
平均合并
20 小时 1 分钟
30 天内合并 PR
11

描述

I have a Maven project that uses JDK 1.8. If I add a dependency, such as net.openhft.lang, containing com.sun.java.tools (without specifying the version) to this project, the language server will generate an error "Missing artifact com.sun.java:tools🫙17.0.6", indicating that it cannot compile.
However, if I compile the project directly using mvn package, there are no errors. I use mvn dependency:tree to find that the version of com.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
  • Operating System: MacOS 11.4
  • JDK version: 1.8.0_151 (Installed in /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home)
  • Visual Studio Code version: 1.76.2
  • Java extension version: v1.16.0
Steps To Reproduce
  1. Create a Maven project with pom.xml
  2. Add a dependency that requires com.sun.java.tools, such as net.openhft.lang (6.6.11 here), into dependencies in pom.xml
  3. Wait for Language Support for Java to reload the project.

sample project: https://github.com/straywarrior/issue_samples/tree/main/vscode-java/maven-test-project
logs:

!ENTRY org.eclipse.jdt.ls.core 4 0 2023-04-06 15:05:37.733
!MESSAGE Error occured while building workspace. Details: 
 message: The container 'Maven Dependencies' references non existing library '/Users/XXX/.m2/repository/com/sun/java/tools/17.0.6/tools-17.0.6.jar'; code: 964; resource: /Users/XXX/maven-test-project;
 message: The project cannot be built until build path errors are resolved; code: 0; resource: /Users/XXX/maven-test-project;
 message: Missing artifact com.sun.java:tools:jar:17.0.6; code: 0; resource: /Users/XXX/maven-test-project/pom.xml; line: 4
Current Result

Language server returns error: Missing artifact com.sun.java:tools🫙17.0.6

Expected Result

No error should occur.

Additional Informations

mvn dependency:tree output:

[INFO] com.straywarrior:maven-test-project:jar:1.0
[INFO] \- net.openhft:lang:jar:6.6.11:compile
[INFO]    +- org.ow2.asm:asm:jar:5.0.3:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.6:compile
[INFO]    +- com.sun.java:tools:jar:1.8.0_151:system
[INFO]    +- net.openhft:compiler:jar:2.2.0:compile
[INFO]    |  +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for duplicate)
[INFO]    |  +- (com.sun.java:tools:jar:1.8.0_151:system - omitted for duplicate)
[INFO]    |  \- org.kohsuke.jetbrains:annotations:jar:9.0:compile
[INFO]    \- org.xerial.snappy:snappy-java:jar:1.1.1.6:compile

VSCode settings.json

    "java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home",
            "default": true
        }
    ]

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从链接的 Maven 示例项目开始,使用列出的 JDK 1.8 运行时和 VS Code 设置重现依赖解析。读取记录的 JDT LS 构建路径错误,并将其对 com.sun.java:tools 的处理与 mvn dependency:tree 进行比较。当示例项目重新加载时不再出现缺少工件错误或构建路径错误,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
build-system, tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。