vscode-java-debug icon indicating copy to clipboard operation
vscode-java-debug copied to clipboard

Failed to get sources when debugging multi module maven project in vscode

Open tarekahf opened this issue 1 year ago • 3 comments

I managed to open a multi-module maven project in VS Code and set up the launch.json correctly. I can debug the project and the breakpoints are respected in the main module. When I set a breakpoint in a referenced module, the execution will break, but I see a decompiled version of the class with the following comments:

 // Failed to get sources. Instead, stub sources have been generated by the disassembler.
 // Implementation of methods is unavailable.

I added the plugin in pom.xml for that module to generate the source from maven and the source. Then I used mvn clean install and the source code JAR was generated successfully under the target folder for the specific module.

I tried to launch the debug again, and nothing worked. I still see the decompiled version of the class.

I configured "sourcePaths" in launch.json to point to the generated source JAR and it didn't and didn't work. I tried to point to the folder, relative path, absolute path, and with/without the filename, but nothing worked.

I appreciate your help to find a resolution to this issue.

Environment
  • Operating System: Windows 11
  • JDK version: 1.8 and 18
  • Visual Studio Code version: latest
  • Java extension version:
  • Java Debugger extension version:
Steps To Reproduce
  1. Open Java multi module maven project in VS code and wait until its fully loaded
  2. Setup the launch config to debug the project.
  3. Set breakpoints in the main and the other referenced modules.
  4. Start debug

[attach a sample project reproducing the error] attach logs

Current Result

Breakpoint works only with the main module. The breakpoint in the other module works but source code is not used.

Expected Result

Breakpoint should work and source code should be displayed for all modules.

Additional Informations

I tried all possible steps to resolve this problem but nothing worked.

tarekahf avatar Nov 23 '22 22:11 tarekahf

Solution found here:

https://github.com/redhat-developer/vscode-java/issues/1315

I want to know if the attach source as per the link above will it persist and where?

tarekahf avatar Nov 24 '22 07:11 tarekahf

Java extension uses lazy policy to fetch source jar for maven dependencies. when the first time you open a library class, it would show a piece of disassembled stub code before the source jar is ready. Could you double check if the source jar is downloaded into your .m2 cache?

testforstephen avatar Feb 10 '23 06:02 testforstephen

How the extension finds the source? If the jar name is say 'myjar.jar' what should be the name of the file with the source? And, how to push the source to the repo? I'm able to generate the source by adding a plugin snippet in pom.xml and I see the source in the target folder.

tarekahf avatar Feb 10 '23 17:02 tarekahf