Vscode-java: Maven projects not detected when gradle found

Created on 26 Mar 2020  路  3Comments  路  Source: redhat-developer/vscode-java

I tried to search the existing issues and could not find this particular issue discussed anywhere. If I open VS Code with a simple Maven project (single pom.xml, no sub-modules) and there are Gradle projects existing within the target folder then the maven project is not detected and its dependencies and source folders are not added to the Java source paths list.

To fix the issue I must run a mvn clean on the project and clean the language server workspace for the maven project to be detected. Afterwards I can build and restart and everything works as expected (and the gradle projects are added to the source list along with the maven projects) as long as I don't clean the workspace and restart without cleaning the maven target folder as well.

Took me several hours to track down why the project stopped working so hopefully I can save someone else from that frustration.

Environment
  • Operating System: Windows 10 Pro
  • JDK version: OpenJDK 1.8
  • Visual Studio Code version: 1.43.2
  • Java extension version: 0.59.0-2069
Steps To Reproduce
  1. Open VS Code and load sample-test folder
  2. Wait for Java Language Server to finish loading
  3. Run command List all Java source paths
  4. Note 5 maven project paths listed
  5. Run mvn package
  6. If you restart VS Code now and list source paths you should see the 5 maven paths and 2 new gradle paths
  7. Clean the Java Language Server Workspace and restart VS Code
  8. Wait for Java Language Server to finish loading and run command List all Java source paths
  9. Note that only 2 gradle paths are listed, the maven paths do not load

sample-test.zip

Current Result

Maven paths do not load if gradle paths are found in subfolders

Expected Result

Both maven paths and gradle paths should load correctly, regardless of additional projects found in subfolders.

Additional Informations

Seems related to #600

Gradle Maven enhancement

Most helpful comment

All 3 comments

@sfariaNG you can try the following settings:

"java.import.exclusions": [
        "**/node_modules/**",
        "**/.metadata/**",
        "**/archetype-resources/**",
        "**/META-INF/maven/**",
        "**/target/**"
    ],

or

"java.import.gradle.enabled": false,

Thanks @snjeza, it looks like setting those exclusions does the trick and intellisense is maintained as long as my .classpath is setup correctly. I still think this is a bug that should be addressed as it doesn't make sense to behave differently in the two scenarios, but this workaround is sufficient in the meantime. Not sure how you all want to handle this ticket.

Was this page helpful?
0 / 5 - 0 ratings