question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

7reactions
jbelfordcommented, Oct 22, 2018

I’m no longer getting this issue when I added my target folders to be excluded from the file watcher.

"files.watcherExclude": {
        "**/target/**": true
},

Not sure if this impacts anything else. I’m guessing its possible that excluding the build folder from gradle might also stop this issue for gradle projects.

1reaction
ledsoftcommented, Mar 2, 2021

I’m no longer getting this issue when I added my target folders to be excluded from the file watcher.

"files.watcherExclude": {
        "**/target/**": true
},

Not sure if this impacts anything else. I’m guessing its possible that excluding the build folder from gradle might also stop this issue for gradle projects.

In which file shall we add this ?

That would be settings.json.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Receiving a gradle build error while trying to run application ...
Regarding to the folder .gradle , it is Project-specific cache directory generated by Gradle. See Project Root Directory.
Read more >
How to fix this error in Visual Studio Code - YouTube
In this video we will fix this error: Open a folder or workspace... (File -- Open Folder ), caused in VS Code (Visual...
Read more >
gradle task assembledebug failed with exit code 1 vscode
The issue was likely caused by the Flutter build that you've downloaded. ... Open project in VS code or Android Studio and open...
Read more >
Bug List - Bugs - Eclipse
443801, Acceleo, User Int, accceleo-inbox, UNCO, ---, Unable to create an Acceleo Project or to toggle the Acceleo nature on an existing project,...
Read more >
New Feature - Release Notes - Java Bug System
modifyOwnProperty; [JDK-8019360] - Cleanup of the javadoc <code> tag in ... [JDK-6921881] - Java Web Start Applications cannot start from folders containing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found