在一个项目中,它有如下maven模块:
A -> A1, A2, module A has 2 sub modules A1 and A2.
A1 -> A2, module A1 has A2 as its dependency
字符串
在A1中运行mvn dependency:tree
,显示以下结果:
[INFO] +- A2:jar:1.0.0-SNAPSHOT:compile
[INFO] | +- co.elastic.clients:elasticsearch-java:jar:8.2.3:compile
[INFO] | | +- org.elasticsearch.client:elasticsearch-rest-client:jar:7.6.2:compile
[INFO] | | | +- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
[INFO] | | | +- org.apache.httpcomponents:httpcore:jar:4.4.14:compile
[INFO] | | | +- org.apache.httpcomponents:httpasyncclient:jar:4.1.4:compile
[INFO] | | | \- org.apache.httpcomponents:httpcore-nio:jar:4.4.14:compile
[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] | | \- org.eclipse.parsson:parsson:jar:1.0.0:compile
[INFO] | +- jakarta.json:jakarta.json-api:jar:1.1.6:compile
型
在A2中运行相同的命令,显示以下结果:
[INFO] +- co.elastic.clients:elasticsearch-java:jar:8.2.3:compile
[INFO] | +- org.elasticsearch.client:elasticsearch-rest-client:jar:7.6.2:compile
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.4.14:compile
[INFO] | | +- org.apache.httpcomponents:httpasyncclient:jar:4.1.4:compile
[INFO] | | \- org.apache.httpcomponents:httpcore-nio:jar:4.4.14:compile
[INFO] | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] | \- org.eclipse.parsson:parsson:jar:1.0.0:compile
[INFO] +- jakarta.json:jakarta.json-api:jar:2.0.1:compile
型jakarta.json-api
在A1中有错误的版本,提示它是从A2中包含的。但是,在A2中,提示显示它没有version 1.1.6 jakarta.json-api
这是git bash CLI的结果,没有使用任何工具。这是我第一次遇到这样的maven依赖行为。所有命令都在mvn clean
之后运行
这是A2 pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>mygroup.ai</groupId>
<artifactId>A</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>A2</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-client -->
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.2.3</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>tlog-web-spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
型
A1的pom:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mygroup.ai</groupId>
<artifactId>A</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>A1</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>A1</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>mygroup.ai</groupId>
<artifactId>A2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- I added this to make it right, although it does not have to be present -->
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>tlog-web-spring-boot-starter</artifactId>
</dependency>
<!--jasypt-->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>mygroup.ai.A.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
型
我使用了一个GUI工具来解析A1 pom.xml,它显示了:
A2: 1.0.0-SNAPSHOT[compile]
- elasticsearch-java: 8.2.3[compile](omitted for conflict with 2.0.1)
- - jakarta.json-api: 1.1.6 [compile]
- - parsson: 1.0.0[compile]
- - - jakarta.json-api: 1.1.6 [compile](omitted for conflict with 2.0.1)
- jakarta.json-api: 1.1.6 [compile](omitted for conflict with 2.0.1)
jakarta.json-api: 2.0.1 [compile]
型
并使用该工具解析A2 pom.xml:
elasticsearch-java: 8.2.3[compile]
- jakarta.json-api: 1.1.6 [compile](omitted for conflict with 2.0.1)
- parsson: 1.0.0[compile]
- - jakarta.json-api: 1.1.6 [compile](omitted for conflict with 2.0.1)
jakarta.json-api: 2.0.1 [compile]
型
1条答案
按热度按时间hjqgdpho1#
Maven基于最近的定义规则解决冲突依赖项。在您的案例中,A2应该使用A作为父依赖项来解决。Maven将使用与声明依赖项的项目最接近的版本。您可以显式控制提供直接依赖项的版本或在其中一个依赖项上写入例外。