Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven warning: duplicate version when using two different types of dependecy of the same artifact

Maven throws a strange warning while builduing our multi-module project. I'm just referencing the jar and test-jar of the same project in another project. Both dependencies have test scope. Im running Maven 3.3.1 and cannot upgrade the version easily.

Does anyone of you have an idea how I could solve the problem without getting this warning from maven?

pom.xml of ProjectA:

    <dependency> <!-- This is line 130 -->
        <groupId>${project.groupId}</groupId>
        <artifactId>projectB</artifactId>
        <version>${project.version}</version>
        <type>test-jar</type>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>projectB</artifactId>
        <version>${project.version}</version>
        <scope>test</scope>
    </dependency>

Warnings from maven (anonymized):

[WARNING] Some problems were encountered while building the effective model for org.group.ProjectA:1.0-SNAPSHOT [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: ${project.groupId}:org.group.ProjectB:jar -> duplicate declaration of version ${project.version} @ org.group.ProjectA, /var/lib/jenkins/jobs/nicejob/workspace/org.group.ProjectA/pom.xml, line 130, column 15

like image 288
MKorsch Avatar asked Apr 21 '16 18:04

MKorsch


People also ask

Which dependency lets maven distinguish between multiple artifacts that are generated from the same project?

Maven can automatically bring in these artifacts, also called transitive dependencies. Version collision happens when multiple dependencies link to the same artifact, but use different versions.

What will happen if the Maven version number of POM XML file does not match with the machine used to install?

Maven won't allow any other either. Build will fail if version is not found.


1 Answers

Looking at test-jar documentation I would say the two artifact are basically the same one, and that the "test-jar" one is not expected to be used aparte from test phase since it contains test classes.

A good approach could be:

  • Leave the "standard" dependencies in compile scope (if you really need it for non-test classes it provides)
  • Use the "test-jar" dependencies as an additional dependency declaration (with test scope) of the surefire-plugin only, so that it's used only by the plugin itself
like image 195
Michele Sacchetti Avatar answered Oct 13 '22 02:10

Michele Sacchetti