Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven assembly pulls wrong dependency

I'm getting an unexpected version of a dependency (1.5.8) when I use the assembly plugin, but nowhere else. In my pom I have:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.0</version>
    </dependency>

When I run dependency:tree or dependency:list, I see the correct version and only the correct version. When I check in Eclipse I see only the correct version.

In my assembly.xml I have:

<dependencySets>
    <dependencySet>
        <outputDirectory>lib</outputDirectory>
    </dependencySet>
</dependencySets>

In the resulting zip, I get slf4j-log4j12-1.5.8.jar. No idea where this is coming from. Any help?

Using maven 3.0.4.

like image 536
Roy Truelove Avatar asked Dec 12 '12 22:12

Roy Truelove


People also ask

What is Maven dependency conflict?

Each dependency that we include in our project might link to other artifacts. 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.

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.

How do you find the parent of transitive dependency?

If you've not declared a dependency in your pom. xml, but it's appearing in your project, it's being imported somewhere as a transitive dependency. You can see exactly which dependency is importing it, by looking at the dependency:tree report, and walking back up the “tree” to find its parent.


1 Answers

This was due to a 'bad' assembly plugin version (2.2-beta-5). My pom.xml did not specify the plugin version. When I explicitly marked it as 2.4 (or the latest version when you read this!), the plugin pulled the correct dependency.

Lesson learned - If you get the following warning in your build:

[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-whatever-plugin is missing
It is highly recommended to fix these problems because they threaten the stability of your build.

.. fix it!

like image 197
Roy Truelove Avatar answered Sep 28 '22 09:09

Roy Truelove