Java 为什么Maven在添加新的依赖项时要重新添加已经存在的依赖项?
在我正在从事的项目中,我的团队拥有以下pom文件:Java 为什么Maven在添加新的依赖项时要重新添加已经存在的依赖项?,java,spring,maven,intellij-idea,Java,Spring,Maven,Intellij Idea,在我正在从事的项目中,我的团队拥有以下pom文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>com.example</groupId>
<artifactId>example-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>example-project</name>
<description>example-project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.13</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.13</version>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-metrics-event-stream</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>google_checks.xml</configLocation>
</configuration>
<executions>
<execution>
<id>checkstyle-check</id>
<phase>validate</phase>
<configuration>
<configLocation>
http://dummy-url.com
</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/Application.*</exclude>
</excludes>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
com.example
请注意,红色突出显示的部分仅在尝试添加spring boot JPA依赖项时出现。没有它,我们的项目运作良好。似乎Maven正在重新添加已经添加的依赖项,这很奇怪,因为例如Hystrix与JPA没有关系
有人知道如何解决这个问题吗?Maven似乎可以通过传递方式添加依赖项,因此您可以获得具有相关版本的额外依赖项
您可以根据需要尝试排除其他依赖项。
请参阅:Maven似乎可以通过传递方式添加依赖项,因此您可以获得具有相关版本的额外依赖项
您可以根据需要尝试排除其他依赖项。
请参阅:要验证是jpa依赖项再次拉入这些JAR,可以在pom.xml所在的目录中运行以下命令
mvn dependency:tree -Dverbose
这将显示depdencies来自何处的输出,只需搜索重复项即可
您可以将排除标记添加到任何可能通过传递方式拉入的库中,如:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
org.springframework.boot
此后,您可以通配符排除可传递依赖项
或者,如果您不想使用*通配符,请明确说明groupId和artifactId。要验证是否是jpa依赖项再次拉入这些JAR,您可以在pom.xml所在的同一目录中运行以下命令
mvn dependency:tree -Dverbose
这将显示depdencies来自何处的输出,只需搜索重复项即可
您可以将排除标记添加到任何可能通过传递方式拉入的库中,如:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
org.springframework.boot
此后,您可以通配符排除可传递依赖项
或者,如果您不想使用*通配符,请明确说明groupId和artifactId。这不是一个错误,而是一个警告
有关重复依赖项的警告
如果您添加了SpringBootJPA依赖项,那么您也间接地添加了其他SpringBoot依赖项。但是如果您严格地添加spring boot,spring boot jpa的间接依赖性将被忽略,并且可能会解决不兼容问题
请删除该spring boot以仅使用spring boot jpa树。这不是一个真正的错误,而是一个警告
有关重复依赖项的警告
如果您添加了SpringBootJPA依赖项,那么您也间接地添加了其他SpringBoot依赖项。但是如果您严格地添加spring boot,spring boot jpa的间接依赖性将被忽略,并且可能会解决不兼容问题
请放下该spring boot,只使用spring boot jpa树。这不起作用,它仍然会产生与问题相同的屏幕截图。我们尝试对其中一个红色下划线的依赖项执行此操作,但什么也没有发生。让我们感到困惑的是Maven不应该将Hystrix依赖项导入到项目中;Hystrix不可能是JPA的可传递依赖项。您是否在intellij中对该项目运行了rebuild?这不起作用,它仍然会产生与问题相同的屏幕截图。我们尝试对其中一个红色下划线的依赖项执行此操作,但什么也没有发生。让我们感到困惑的是Maven不应该将Hystrix依赖项导入到项目中;Hystrix不可能是JPA的可传递依赖项。您是否在intellij中对项目运行了rebuild?Hystrix是您项目的依赖项(在您发布的Pom中)。你为什么不期待呢?歇斯底里是你项目的一个依赖项(在你发布的Pom中)。你为什么不期待呢?