dbp
dbp

Reputation: 101

How to debug conflicting dependencies in Maven project

When I build my Maven-managed Java project, two versions of the same artifact are installed into the build (a war file). I am pretty sure that it doesn't matter, but the artifact in question is com.fasterxml.jackson.core:jackson-annotations versions 2.7.3 and 2.9.7.

When I run mvn dependency:tree -Dverbose, there are no occurrences of jackson-annotations:2.7.3, indeed, there are no occurrences of the string 2.7.3 anywhere in the resulting output.

My question is, how do I proceed to debug this problem? I believed that the dependency:tree goal would give me the full set of transitive dependencies. Is this belief correct? If not, what would?

For the record, on my local machine the new version of the library is found and everything works, but when deployed to another machine the deployment is broken because that machine finds the old version of the library.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mygroup</groupId>
    <artifactId>something</artifactId>
    <version>0.0.48</version>
    <packaging>war</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>mygroup</groupId>
        <artifactId>a</artifactId>
        <version>0.0.34</version>
    </dependency>

    <dependency>
        <groupId>mygroup</groupId>
        <artifactId>b</artifactId>
        <version>0.0.36</version>
    </dependency>

     <!-- Jersey -->

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.1.12</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>


    <dependency>
        <groupId>org.glassfish.jersey.test-framework</groupId>
        <artifactId>jersey-test-framework-core</artifactId>
        <version>2.25.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.25.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.25.1</version>
        <scope>test</scope>
    </dependency>

    <!-- Jersey Test Framework -->

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.25.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.25.1</version>
        <scope>test</scope>
    </dependency>

     <dependency>
        <groupId>
            org.glassfish.jersey.test-framework.providers
        </groupId>
        <artifactId>
            jersey-test-framework-provider-grizzly2
        </artifactId>
        <version>2.25.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>2.25.1</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<repositories>
    <repository>
        <id>myrepository</id>
        <name>My repository name</name>
        <url>myrepositoryurl</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>


<build>
    <sourceDirectory>src/main</sourceDirectory>
    <testSourceDirectory>src/test</testSourceDirectory>
    <resources>
        <resource>
            <directory>.</directory>
            <includes>
                <include>pom.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
   </plugins>
 </build>
</project>

Upvotes: 1

Views: 3319

Answers (3)

dbp
dbp

Reputation: 101

Well.

This is embarrassing.

This had nothing to do with Maven or its dependency computation. Rather I had a WEB-INF/lib folder in my project, which contained the conflicting libraries, and which was being merged into the .war file at build time.

Thanks everyone for looking at this and trying to help with a chimerical problem.

Upvotes: 1

Laird Nelson
Laird Nelson

Reputation: 16196

You can run the dependency:tree goal in such a way that you ensure it is using the latest version of its own innards (as you can any Maven plugin you can run from the command line):

$ mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:tree

(In Ancient Times™ the dependency:tree goal's dependency resolution algorithm may not have matched that actually used by Maven itself. It might be that you are using an ancient version of the plugin unknowingly.)

Upvotes: 0

You can without debugging just expanding all you project dependencies and looking by the one that you are look enter image description here

then on that dependency you can exclude some inner libraries in you pom.xml ie:

        <dependency>
        <groupId>com.core</groupId>
        <artifactId>transactions-core</artifactId>
        <version>${utransactions.core}</version>
<!-- this exclusion -->
        <exclusions>
            <exclusion>
                <artifactId>log4j-api</artifactId>
                <groupId>org.apache.logging.log4j</groupId>
            </exclusion>
            <exclusion>
                <artifactId>log4j-core</artifactId>
                <groupId>org.apache.logging.log4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>

Upvotes: 0

Related Questions