I am having a maven (3.6.0) project based on java 11 with the following structure (which works fine on the commandline!):
src/main/java/
module-info.java
/de/test/tp/TP.java
src/test/java/
/de/test/tp/test/TPTests.java
The module-info.java looks as following:
module de.test.tp
{
exports de.test.tp;
requires org.apache.logging.log4j;
}
TP.java:
package de.test.tp;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TP
{
private static final Logger LOGGER = LogManager.getLogger(TP.class);
public TP()
{
super();
LOGGER.info("test");
}
}
TPTests.java:
package de.test.tp.test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import de.test.tp.TP;
public class TPTests
{
private static final Logger LOGGER = LogManager.getLogger(TP.class);
public TPTests()
{
super();
}
@Test
public void defaultConstructor()
{
final TP tp = new TP();
assertNotNull(tp, "Default constructor failed!");
}
}
Last but not least the important parts of pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<fork>true</fork>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<optimize>false</optimize>
<debug>true</debug>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.2</version>
</dependency>
</dependencies>
When I now say (from within Eclipse) "maven/update project" the eclipse puts all maven dependencies to the classpath. After recompiling eclipse tells me:
The package org.apache.logging.log4j is accessible from more than one module: <unnamed>, org.apache.logging.log4j
for both org.apache.logging.log4j
imports.
So the question is, how to fix that?
Update 1
What I really want is a clear project structure for a java modules project that is based on maven, works in eclipse and supports white- and blackbox testing. Can somebody give me such a project skeleton?
Update 2
Or is my problem that eclipse does not have multi-module support as I read in some articles? - Which also would lead me back to the question of Update 1.
Update 3
Shortened the whole question and added complete (shortened) file contents.
Note 1
During all my testing for example with having a seconds module-info.java under test/java/
I found that eclipse 2019-03 is very instable and has bugs! For example - Sometime when trying to delete the module-info.java under test - Eclipse was not able to delete it. Another effect was that when editing the module-info.java with the test path eclipse also edit's the module-info.java under the main path. This means that within the main module-info.java I found that the exort has changed to de.test.tp.test - when I fixed that (in eclipse editor) I could not save the file. When I fixed that in an external editor and refresh/clean the project eclipse still tells me that the de.test.tp.test would not exist - so I have to delete the errors manually from the marker tab.
So from my point of view eclipse 2019-03 has some bugs regarding the handling of java modules.
Note 2
As you can see from the comments below @howIger has reported this as a bug in Eclipse.
Note 3
Looks to me like it is fixed now in eclipse 2019-06 :)