I have two Maven projects A and B, where project B is nested in project A. The structure looks like the following:
Project A: src/test/java: DependencyClass.java Project B: src/test/java: MyTest.java pom.xml pom.xml I'm trying to import DependencyClass.java (project A) into MyTest.java (project B), and be able to invoke the methods in DependencyClass.java from MyTest.java. But when I tried to package project B, it failed at the compile phase:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project : Compilation failure: [ERROR] MyTest.java:[7,41] package XXX does not exist [ERROR] MyTest.java:[17,9] cannot find symbol [ERROR] symbol: class DependencyClass.java I have found some answers such as this and this, and I have done the following:
added the maven-jar-plugin with a goal of "test-jar" in the pom.xml of project A
added the dependency to project A in project B's pom.xml, and declared type as "test-jar" and scope as "test".
Eclipse is able to resolve DependencyClass.java without giving errors, but it just failed when I tried to build with Maven. Any suggestion or idea on what I might be missing? Thanks in advance
Edit: I have also tried adding another dependency in project B's pom.xml, with the following scope and type:
<scope>compile</scope> <type>jar</type> But I got more errors when building project B - now it even starts to complain about jUnit and other built-in classes.