Error: The import XXX cannot be resolved
I'm facing this issue in Java 11 while trying to migrate from java 8.
Parent Project X:
Project A:
Project Aa:
src/test/java:
MyTestA.java
pom.xml
pom.xml
Project B:
Project Ba:
src/test/java:
MyTestB.java
pom.xml
pom.xml
pom.xml
Here I'm trying to access MyTestA.java from MyTestB.java
- I even tried the same as described in this question, but still faced the same issue. Maven compile error - unable to resolve test dependency from another local project
What Have I tried:
Remove the <scope> tag. So now in project Ba pom.xml, I declared two dependencies of project A, one with <type>jar</type> and another with <type>test-jar</type>, and both don't have declared.
In project A's and project Aa pom.xml, the execution goal of the "maven-jar-plugin" should specify both "jar" and "test-jar".
Still facing the same issue..
But I'm able to access classes from Project Aa's src/main/java packages
Test classes of an artifact are not exposed, only those in
src/mainare.In order to achieve what you want, you can add another module to your project (let's say
Project C), in which you will put the common code you need in both test classes. This code will be insrc/main/java.Then you can add this module as a test dependency for
Project AaandProject Ba.