Java 意外的可传递依赖项版本

Java 意外的可传递依赖项版本,java,maven,mockito,dependency-management,Java,Maven,Mockito,Dependency Management,使用spring boot设置一个干净的Maven项目,以便使用JUnit4和5进行测试,我最终得到以下依赖项: <properties> <junit-jupiter.version>5.5.2</junit-jupiter.version> <spring-framework.version>5.2.0.RELEASE</spring-framework.version> <spring-boot.ve

使用spring boot设置一个干净的
Maven
项目,以便使用
JUnit
4和5进行测试,我最终得到以下依赖项:

<properties>
    <junit-jupiter.version>5.5.2</junit-jupiter.version>
    <spring-framework.version>5.2.0.RELEASE</spring-framework.version>
    <spring-boot.version>2.2.0.RELEASE</spring-boot.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>${spring-boot.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-swing</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
</dependencies>
<dependencies>
    <!-- Module dependencies -->
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>OpenPatricianUtilities</artifactId>
    </dependency>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>GameEvent</artifactId>
    </dependency>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>MarvinFXEssentials</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- Spring Framework -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
    </dependency>
    <!-- Other libraries -->

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>ch.sahits</groupId>
        <artifactId>sahitsUtil</artifactId>
    </dependency>

    <!-- Test -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>OpenPatricianData</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>OpenPatricianTestUtilities</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
在不同的模块/项目上,我有以下依赖项:

<properties>
    <junit-jupiter.version>5.5.2</junit-jupiter.version>
    <spring-framework.version>5.2.0.RELEASE</spring-framework.version>
    <spring-boot.version>2.2.0.RELEASE</spring-boot.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>${spring-boot.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-swing</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
</dependencies>
<dependencies>
    <!-- Module dependencies -->
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>OpenPatricianUtilities</artifactId>
    </dependency>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>GameEvent</artifactId>
    </dependency>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>MarvinFXEssentials</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- Spring Framework -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
    </dependency>
    <!-- Other libraries -->

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>ch.sahits</groupId>
        <artifactId>sahitsUtil</artifactId>
    </dependency>

    <!-- Test -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>OpenPatricianData</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>OpenPatricianTestUtilities</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
通过
spring boot starter测试
在3.1.0版中定义
Mockito
。然而,项目junit55具有版本1.9.10的字节伙伴依赖性,而OpenPatricianModel具有版本1.10.1的字节伙伴依赖性。该依赖项在项目中没有明确定义


我怎么可能对OpenPatricianModel有不同的字节伙伴依赖关系,我怎么才能找到它的来源。

字节伙伴依赖关系被至少一个比
org.springframework.boot:spring boot starter test
多的依赖关系临时拉入。通过您的
OpenPatricianModel
的依赖关系树中的byte buddy范围,您可以看到这一点。请注意,范围是
compile
,而不是
test

找出哪个依赖项正在引入它的最佳方法是在spring boot starter测试的声明中添加对
byte buddy
依赖项的排除。比如:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>net.bytebuddy</groupId>
            <artifactId>byte-buddy</artifactId>
        </exclusion>
        <exclusion>
            <groupId>net.bytebuddy</groupId>
            <artifactId>byte-buddy-agent</artifactId>
        </exclusion>
    </exclusions>
</dependency>

org.springframework.boot
弹簧起动试验
测试
net.bytebuddy
字节伙伴
net.bytebuddy
字节好友代理

然后,通过再次运行
mvn-dependency:tree
,您应该能够看到哪个依赖项正在引入。请注意,可能不止一个,在这种情况下,您将不得不再次进行相同的练习。

真奇怪。您是否明确定义了任何存储库?或者您的父项目是否定义了可能导致mockito的不同pom文件的存储库?(这不太可能是因为这是一个发布版本)@ernest_k:没有明确定义存储库。junit55没有父pom,而OpenPatricianModel有一个处理依赖关系管理的pom。