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

Self referencing maven modules should not trigger an infinite loop in vscode

Open boriswaguia opened this issue 3 years ago • 2 comments

Vscode enters an infinite loop while trying to compile a falsy module setup. It should instead break the build should break with an error stating that a module is self-referencing itself the same way the maven cli report it.

Environment
  • Operating System: OSX BIg Sur
  • JDK version: OpenJDK 11.0.8 2020-07-14
  • Visual Studio Code version: [Version: 1.56.2 Commit: 054a9295330880ed74ceaedda236253b4f39a335]
  • Java extension version:
Steps To Reproduce
  1. Create a parent maven project with packaging type pom - parent
  2. Create a submodule (module-1) project with the packaging type 'jar' in the previous parent project
  3. Add a dependency of module-1 in parent with the save version (${project.version})
  4. See the error: Vscode will enter an infinite loop trying to resolve the dependency

Sample project reproducing the error

test-self-ref.zip

Current Result

The build will never get past the 339/1000 as displayed in the console (infinite loop)

Screenshot 2021-06-10 at 10 40 39
Expected Result

Build should terminate with error as done bymaven when using the cli.

Screenshot 2021-06-10 at 11 02 07
Additional Informations

boriswaguia avatar Jun 11 '21 17:06 boriswaguia

I face with same error (infinite java building) in multi module maven project with vscode + java in dev containers. My dev containers JSON is :

{ "name": "Java", "build": { "dockerfile": "Dockerfile", "args": { "VARIANT": "0.151-8", "INSTALL_MAVEN": "true", "INSTALL_GRADLE": "false", "INSTALL_NODE": "false", "NODE_VERSION": "lts/*" } },

SnowISmirnov avatar Jul 27 '21 07:07 SnowISmirnov

I am seeing the same behavior without self-referencing modules. Perhaps a different issue, please feel free to split into a different issue.

Some of the projects have Maven plugins that run in the generate-sources phase and produce source code in ./target/generated-sources. VScode behavior in this case is "refresh workspace", followed by "try building again", which in turn results in generate-sources targets re-executed and the whole thing starts again.

I attempted disabling the M2E mapping for the plugins that generate code to avoid this problem:

<executions>
<execution>
-<?m2e execute onConfiguration,onIncremental?>
+<?m2e execute?>
...
</execution>
...

Per M2E documentation onConfiguration, onIncremental means that the plugin should run every time the project configuration changes and also with every incremental build. It looks like that onIncremental causes the problem here, sending vscode Maven integration into infinite loop. I didn't have a chance to confirm if Eclipse itself has a different behavior, but since other folks in my team didn't see any issues with it, and some use Eclipse, I'd suspect this may be vscode-specific.

Edit: The solution above is less than ideal for a number of reasons, notably now code generation won't run incrementally at all, which means one needs to do mvn clean generate-sources in the console periodically.

dbarvitsky avatar Jul 15 '22 17:07 dbarvitsky