0

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:

  1. added the maven-jar-plugin with a goal of "test-jar" in the pom.xml of project A

  2. 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.

4
  • Have you installed the project projectA-test.jar in your repository ?? Commented Sep 28, 2021 at 5:11
  • @nhatnq Yes I have run "mvn clean install" and installed the test jar file successfully. Commented Sep 28, 2021 at 5:22
  • It would be good if you could post your pom content (especially the one for the project B). Commented Sep 28, 2021 at 15:34
  • Thank you both. I have resolved my error. The fix was to remove the <scope> tag. So now in project B's 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 <scope> declared. Commented Sep 28, 2021 at 20:35

1 Answer 1

0

I have resolved my error. The fix was to remove the <scope> tag. So now in project B's 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 <scope> declared.

In project A's pom.xml, the execution goal of the "maven-jar-plugin" should specify both "jar" and "test-jar".

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.