问题描述
构建Maven管理的Java项目时,会将相同工件的两个版本安装到构建中(war文件)。我敢肯定这没关系,但是所讨论的工件是 com.fasterxml.jackson.core:jackson-annotations 版本 2.7.3和2.9.7
当我运行 mvn依赖项:tree -Dverbose 时,没有出现 jackson-annotations:2.7.3 ,实际上,没有出现任何字符串 2.7.3 。
我的问题是,如何继续调试此问题?我相信 dependency:tree 目标将为我提供完整的传递依赖项集。这个信念正确吗?如果没有,那会是什么?
作为记录,在我的本地计算机上找到了该库的新版本,并且一切正常,但是当部署到另一台计算机时,该部署被破坏了,因为该计算机找到了该库的旧版本。
<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>
解决方法
您可以在不调试的情况下扩展所有项目依赖项,并根据自己的外观进行查看
然后基于该依赖性,您可以在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>
,
您可以通过运行dependency:tree
goal的方式来确保它使用自己内部版本的最新版本(因为您可以从命令行运行任何Maven插件):
$ mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:tree
(在Ancient Times™中,dependency:tree
目标的依赖关系解析算法可能与Maven本身实际使用的算法不匹配。可能是您在不知不觉中使用了古老版本的插件。)
好吧。
这很尴尬。
这与Maven或其依赖项计算无关。而是在我的项目中有一个WEB-INF / lib文件夹,其中包含冲突的库,并且在构建时已合并到.war文件中。
感谢大家研究并尝试解决嵌合体问题。