redhat-developer / redhat-developer/vscode-java

When having VS Code open on a project that has a generated code srcDir, and running gradle commands from the command-line in that same folder, lock contention issues cause corrupted artifacts

未关闭
#344 10 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Expected Behavior

I'm using VS Code 1.17.2 + vscode-java 0.12.0, gradle 4.2.1 to build a Java 8 SpringBoot application om macOS 10.12.6. The build uses an xjc ant task to generate .java files from a few .xsd documents in the resources directory. I've verified that in my case, 11 ObjectFactory.java files are generated, and consequently, 11 ObjectFactory.class files are compiled correctly. I would expect all of those class files to end up in my resulting .war artifact.

Current Behavior

A random number of ObjectFactory.class files end up in the .war file. To verify this, see how to reproduce below.

Context

The issue occurs when vscode is open on a project which contains a generated code folder, specified as a srcDir entry in the build.gradle, and a terminal on the same project is used to run gradle commands. It looks like gradle from the command-line is competing with vscode-java/eclipse-jdt-ls/buildship for locks on files.

Note that it has been observed that specifying options.fork in the compileJava {..} section also works around the problem, although I suspect that only happens due to timing (i.e, think this is a race condition/lock contention of sorts).

Steps to Reproduce
  1. Git clone reproducer (git clone git@github.com:rubin55/reproducer.git)
  2. Open reproducer as folder in vscode
  3. Let vscode initialize, open a few Java files to see that class lookup works
  4. In particular, open a .java file from the generated source folder
  5. Open a terminal and cd to the reproducer
  6. Run this, a few times in a row:
gradle clean build && echo I found $(unzip -l build/libs/*.war | grep ObjectFactory.class | wc -l) ObjectFactory objects in archive while $(find build/classes/ -type f -name ObjectFactory.class | wc -l) were compiled and $(find build/generated/ -type f -name ObjectFactory.java | wc -l) java files where generated

Example output:

I found 1 ObjectFactory objects in archive while 11 were compiled and 11 java files where generated
  1. If the issue manifests, you will see that the resultant .war file will have missing ObjectFactory.class files (see message above).
  2. Observe vscode-java .log file and see backtraces that coincide with this issue. See attached vscode-java.log.
Your Environment

VS Code 1.17.2
VS Code Java 0.12.0
Gradle 4.2.1
Java 8 r144
macOS 10.12.6

贡献指南

打开贡献指南

从这里开始

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

调研方向

从复现仓库、其中的 build.gradle 以及报告中描述的生成源代码目录开始。在 VS Code 和 vscode-java 处于打开状态时反复运行 gradle clean build 命令,然后比较生成的 Java 文件、编译后的类和 WAR 内容;检查附加的 vscode-java.log,查找相应的回溯。复现的构建始终包含所有生成的 ObjectFactory.class 文件,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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