Handle module projects with separate module-info.java for main and test sources
See original GitHub issueHere is a Java 11 maven module project: https://github.com/microsoft/gctoolkit. The project is a multi-module maven project. One submodule is “api”, see its file structure as follows. It describes the module-info.java file in the main sources and the test sources respectively.
api
├───src
│ ├───main
│ │ ├───java
│ │ │ │ module-info.java
│ │ │ └───com.microsoft.gctoolkit
│ │ │ GCToolKit.java
│ └───test
│ ├───java
| | | module-info.java
│ │ └───com.microsoft.gctoolkit.test
│ │ Test.java
However, when opening this project in VS Code, it doesn’t work. It reports a compile error: “The project was not built due to “Build path contains duplicate entry: ‘module-info.java’ for project ‘api’”. Fix the problem, then try refreshing this project and building it since it may be inconsistent”. It doesn’t support multiple module-info.java files in one Java project.
The same project works in maven command line. There should be some gap in the JDT compiler that needs to be fixed.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (1 by maintainers)
The problem is that there is no standard way at the JEP level to tell the tooling how to handle test sources. Each tool has to tweak it in their own way. The upstream JDT issues https://bugs.eclipse.org/bugs/show_bug.cgi?id=520667 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=559601 are still under discussion, waiting for a spec or standard to deal with it.
@brunoborges There is a workaround to unlock your use of VS Code for
gctoolkit
. Add a profile as follows to your root pom.xml to exclude the test source module-info.java from the compiler configuration.This can bypass the duplicate module-info.java check, and the Java tooling will use the classpath way to handle test files. This profile only takes effect in VS Code environment, and not affect your maven command line. If you want, i can submit a PR in gctoolkit project.
Related issue - https://github.com/redhat-developer/vscode-java/issues/2090#issuecomment-909767806