简体   繁体   English

如何调试Maven项目中的冲突依赖

[英]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).当我构建我的 Maven 管理的 Java 项目时,同一个工件的两个版本被安装到构建中(一个 war 文件)。 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 .我很确定这无关紧要,但有问题的工件是com.fasterxml.jackson.core:jackson-annotations版本2.7.3 和 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.当我运行mvn dependency:tree -Dverbose 时,没有出现jackson-annotations:2.7.3 ,实际上,在结果输出中的任何地方都没有出现字符串2.7.3

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.我相信dependency:tree目标会给我完整的传递依赖集。 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>

You can without debugging just expanding all you project dependencies and looking by the one that you are look您可以无需调试,只需扩展所有项目依赖项并查看您所看到的依赖项在此处输入图片说明

then on that dependency you can exclude some inner libraries in you pom.xml ie:然后在该依赖项上,您可以排除 pom.xml 中的一些内部库,即:

        <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>

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):您可以以确保它使用自己内部结构的最新版本的方式运行dependency:tree目标(就像您可以从命令行运行的任何 Maven 插件一样):

$ 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.) (在Ancient Times™ 中, dependency:tree目标的依赖解析算法可能与 Maven 本身实际使用的算法不匹配。可能是您在不知不觉中使用了旧版本的插件。)

Well.好。

This is embarrassing.这很尴尬。

This had nothing to do with Maven or its dependency computation.这与 Maven 或其依赖计算无关。 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.相反,我的项目中有一个 WEB-INF/lib 文件夹,其中包含冲突的库,并在构建时合并到 .war 文件中。

Thanks everyone for looking at this and trying to help with a chimerical problem.感谢大家看到这个并试图帮助解决一个嵌合问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM