vanval
vanval

Reputation: 1027

Maven Compilation error if two different jars have the same package names

I have two different jars asource.jar and btest.jar. btest.jar has a com.foo.test class which tests a class com.foo.source in asource.jar.

When I try running mvn clean install against btest.jar, I get compilation error saying that the class com.foo.source.java does not exist. I analyzed and came to the conclusion that maven is searching for source.java in the com.foo package in btest.jar and not finding it there it fails. It does not even try to search for the class in a similarly named package in asource.jar.

maven exclude, etc will not work here since there is nothing I can exclude. Is there some way to make maven search recursively in multiple jars for the same package name?

Upvotes: 0

Views: 999

Answers (1)

Gab
Gab

Reputation: 8323

you have to add your asource module as a dependency of btest module

<project [...]>
 <groupId>com.foo</groupId>
 <artifactId>btest</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>jar</packaging>

 [...]
 <dependencies>
   <dependency>
    <groupId>com.foo</groupId>
    <artifactId>asource</artifactId>
    <version>1.0-SNAPSHOT</version>
  </dependency>
 </dependencies>

Upvotes: 1

Related Questions