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

12,657

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
Share:
12,657
MKorsch
Author by

MKorsch

I'm just a student needing help from time to time...

Updated on June 30, 2022

Comments

  • MKorsch
    MKorsch almost 2 years

    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