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

Maven project inside another maven project not recognized

Open richardswesterhof opened this issue 2 years ago • 6 comments

When you have a maven project inside another maven project, only the top level project is properly recognized in the java projects view. However, if the sub-project is opened in another window by itself, the project is properly recognized

Environment
  • Operating System: Fedora 38
  • JDK version: openjdk 17.0.7
  • Visual Studio Code version: 1.81.0
  • Java extension version: 1.21.0
Steps To Reproduce
  1. Create new maven project (using maven for java extension)
  2. Create new maven project inside project from step 1. Example structure below:
test_project/
    src/
        main/
             java/
                TestMain.java
    pom.xml
    sub_project/
        src/
            main/
                java/
                    SubMain.java
        pom.xml
  1. Import Java Projects into Workspace
  2. Observe only test_project is properly imported in this case
  3. Open a new window: File > New Window
  4. Inside new window, open sub_project: File > Open Folder > select sub_project
  5. Observe sub_project can now be recognized as a java project
Current Result

Only top level projects are recognized, projects inside projects are not. This leads to the warning SubMain.java is not on the classpath of project test_project, only syntax errors are reported and many features of the extension not working

Expected Result

Projects are recursively detected by their pom files and the extension features can be used for projects inside projects

richardswesterhof avatar Aug 09 '23 08:08 richardswesterhof

We have found issues that are potential duplicates:

  • #3221 (61.25%)

If any of the issues listed above are a duplicate, please consider closing this issue & upvoting/commenting the original one. Alternatively, if neither of the listed issues addresses your feature/bug, keep this issue open.

github-actions[bot] avatar Aug 09 '23 08:08 github-actions[bot]

To recognize nested projects, you need the top project to be have "pom" packaging, and declare the sub project as a module. "pom" projects can't contain java code.

fbricon avatar Aug 09 '23 09:08 fbricon

Maybe I shouldn't have called it a sub project, I don't want the projects to be "connected" per se; I don't need to use the "sub" project inside the top project. They are separate projects, but for the directory structure it makes sense to store project A inside project B, other than that they are not related. Would that be possible?

richardswesterhof avatar Aug 09 '23 09:08 richardswesterhof

no, as soon as the non-"pom" top project is detected, we stop crawling down to find other projects

fbricon avatar Aug 09 '23 09:08 fbricon

Could a setting be added to make this configurable? Or allow users to manually select directories to import as a java project?

richardswesterhof avatar Aug 09 '23 10:08 richardswesterhof

I have a monorepo setup with multiple subprojects on different languages, would be good to have some way to support this.

gemyago avatar Jul 01 '24 18:07 gemyago