redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 442 forks source link

Multi-module Maven project does not work #1248

Open ccarv opened 4 years ago

ccarv commented 4 years ago

I created a multi-module Maven project and tried to open the root folder in Visual Studio Code. When I try to work with any of the sub-modules, I do not get any linting, formatting, refactoring, etc... I tried Add Folder to Java Source Path but that does not work either. I have no issues working with this project in other IDE's, including Eclipse.

Environment
Steps To Reproduce
  1. Clone example project:

    git clone https://github.com/hashdelta/stix-pattern-evaluator-examples.git
    cd stix-pattern-evaluator-examples
    git checkout develop
  2. Open project in VSCode

Current Result

The plugin does not recognize the children modules, thus does not provide any kind of Java semantics support - no linting, formatting, refactoring, etc...

Expected Result

You should be able to get semantics support for any Java class when you open the parent. It should be one cohesive project.

Additional Informations

The only way to work with the sub modules is by opening the module in its own VSCode instance. This does not work for me, as one of my projects consists of over 20+ modules.

I have verified in Eclipse, NetBeans, and IntelliJ that the GitHub project has no issues.

snjeza commented 4 years ago

I can't reproduce the issue. Can you attach server logs? See https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#turn-on-message-tracing-between-vs-code-and-the-java-language-server

ccarv commented 4 years ago

Attached the server log. vscode-server.log

ccarv commented 4 years ago

@snjeza It looks like clearing the workspaceStorage fixed my issue. Does this deserve a close?

snjeza commented 4 years ago

It looks like clearing the workspaceStorage fixed my issue. Does this deserve a close?

@hashdelta yes, you can close the issue.

ccarv commented 4 years ago

@snjeza Revisiting this. What is the proper way to initialize a new maven sub module in VSCode? I am manually creating the POM and folder hierarchy, and VSCode does not recognize it unless I clear the workspaceStorage directory, which is a non-solution.

snjeza commented 4 years ago

Revisiting this. What is the proper way to initialize a new maven sub module in VSCode? I am manually creating the POM and folder hierarchy, and VSCode does not recognize it unless I clear the workspaceStorage directory, which is a non-solution.

Related to https://github.com/eclipse/eclipse.jdt.ls/pull/901 @ccarv could you try https://github.com/snjeza/vscode-test/blob/master/java-0.56.1.vsix?raw=true

ousiax commented 3 years ago

I have the same problem. What can I do to solve it is to reopen the root folder again after create a new sub module.

Btw, I think the vscode should refresh the project automatically.

holmofy commented 3 years ago

Me too. Open multi-module project will have a lot of error

brunoborges commented 3 years ago

Facing issue too with the microsoft/gctoolkit project (multi-module, and each has its own module-info.java).

go-fish-wxy commented 2 years ago

It looks like clearing the workspaceStorage fixed my issue. Does this deserve a close?

@hashdelta yes, you can close the issue.

Hi, I am just facing same issue, kindof no idea how to make vs code recognize the project folder and all sub folders and files as a multi-module maven project, e.g. pom file in sub module report error "could not find dependency" What steps shall I take to make project workable in vs code until I can debug the source file

tonyvperez commented 1 year ago

It appears this issue hasn't received prioritization needed for resolution. I'm working on a project that requires the building of such a repo with nested modules and there isn't a viable solution to develop with intellisense intact. Is there any plans to work in this issue in the near future?

rossinineto commented 1 year ago

For me, source folders from submodules doesn´t appear after added a java project multi modules. For workaround, I downgraded the extension "Project Manager for Java" (https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency) to version 0.21.2

Captura de tela 2023-08-17 095642

rossinineto commented 1 year ago

Updated "Project Manager for Java" to v0.23.1 and occurs the problem bellow:

Captura de tela 2023-09-03 095215

crowmagnumb commented 12 months ago

I have all my code in a mono-repo. All my Java code is in modules in a sub-directory called java. Despite the mono-repo I've been using Eclipse for all my Java dev and VSCode for everything else. BUT I want to consolidate it all under VSCode but I just can't get the Java code to work right. There is a single parent pom.xml that lists all of the sub-modules which hierarchically depend on one another. If I open in VSCode the folder containing just the lowest sub-module in the stack, so that it is alone in the workspace and only depends on 3rd-party code listed in it's pom.xml, the Java and maven plugins all work right out of the box and I can edit and debug just fine.

BUT I can't figure out how to get VSCode to recognize the java and maven code if I open the full repo. Does this just not work?

snjeza commented 12 months ago

There is a single parent pom.xml

@crowmagnumb Could you show this pom.xml?

crowmagnumb commented 12 months ago

@snjeza Here is my parent pom.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.animalus</groupId>
  <artifactId>auroot-parent</artifactId>
  <version>2.0.0</version>
  <packaging>pom</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- Skipping javadoc by default. If you want to run the javadoc run...
            mvn -Dmaven.javadoc.skip=false javadoc:javadoc -->
    <maven.javadoc.skip>true</maven.javadoc.skip>
    <flyway.version>9.21.1</flyway.version>
    <jackson.version>2.15.2</jackson.version>
    <!-- <shiro.version>1.12.0</shiro.version> -->
    <shiro.version>2.0.0-alpha-3</shiro.version>
    <junit.version>5.10.0</junit.version>
    <!-- upgrade these together depending on which version of springframework
             is used by the version of springboot or else you may get duplicate
             libraries in the final packaged jar. Annoyingly springsession is
             on a different schedule, so just bump to its latest I guess -->
    <!-- <springcore.version>5.3.21</springcore.version> -->
    <springboot.version>3.1.2</springboot.version>
    <springsession.version>3.1.1</springsession.version>
  </properties>

  <modules>
    <module>auroot-core</module>
    <module>auroot-http</module>
    <module>autravel</module>
    <module>autravel-http</module>
    <module>critterspot-core</module>
    <module>critterspot-admin</module>
    <module>critterspot-http</module>
    <module>critterspot-server</module>
    <module>crowdb</module>
    <module>crowjson</module>
    <module>crowlang</module>
    <module>auhttp</module>
    <module>auzooniverse</module>
  </modules>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.5.0</version>

        <configuration>          <reportOutputDirectory>${project.basedir}/target/${project.artifactId}-${project.version}</reportOutputDirectory>
          <destDir>javadoc</destDir>
          <show>private</show>
        </configuration>

        <executions>
          <execution>
            <phase>install</phase>
            <goals>
              <goal>javadoc</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.11.0</version>
        <configuration>
          <release>17</release>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>3.1.2</version>
        <configuration>
          <argLine>--illegal-access=permit</argLine>
        </configuration>

        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-maven-plugin</artifactId>
        <version>${flyway.version}</version>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.1.2</version>
        <configuration>
          <argLine>--illegal-access=permit</argLine>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>

      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.16.0</version>
        <configuration>
          <generateBackupPoms>false</generateBackupPoms>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
          <execution>
            <id>enforce-versions</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireMavenVersion>
                  <version>3.2.5</version>
                </requireMavenVersion>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.3.1</version>
        <configuration>
          <encoding>UTF-8</encoding>
          <nonFilteredFileExtensions>
            <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
        </configuration>
      </plugin>

    </plugins>

  </build>

</project>

Note: The Java/Maven plugins recognize this as a java project (it shows up in the java projects list) BUT the sub-projects (modules) and their poms are not recognized.

snjeza commented 12 months ago

BUT the sub-projects (modules)

Could you show your workspace and user settings.json and your logs - Enable Logging?

crowmagnumb commented 11 months ago

@snjeza Thank you! I didn't know how to set the logs to debug nor read them. Through the logs I found out that all of my .project files from Eclipse all had <!DOCTYPE xml> on the 2nd line and that was causing it grief. No idea how they got there (well probably auto-added by Eclipse) but I removed those lines, reloaded the Java extension and voila it works!!! Thank you!