Exception in thread "Thread-2" java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;) for PACT tests

Exception in thread "Thread-2" java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;) for PACT tests

我在尝试 运行 使用 Java 进行一些 PACT 测试时遇到了这个 kotlin 异常,但我不确定如何修复它。

这里报错:

Exception in thread "Thread-2" java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;)[B

编辑

我已经更新了我的 PACT 依赖项以使用更多最新版本,但我仍然遇到同样的问题,但是只有当我有以下依赖项作为它的一部分并且不确定为什么时才会出现。

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
</parent>

这是我当前的 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>

<groupId>com.hmhco</groupId>
<artifactId>update-catalog</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
</parent>

<properties>
    <rest-assured.version>3.0.0</rest-assured.version>
    <json-schema-validator.version>3.3.0</json-schema-validator.version>
</properties>

<dependencies>
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>${rest-assured.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>json-schema-validator</artifactId>
        <version>${json-schema-validator.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>au.com.dius</groupId>
        <artifactId>pact-jvm-consumer-junit5</artifactId>
        <version>4.0.10</version>
    </dependency>
    <dependency>
        <groupId>au.com.dius</groupId>
        <artifactId>pact-jvm-provider-junit</artifactId>
        <version>4.0.10</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>au.com.dius</groupId>
            <artifactId>pact-jvm-provider-maven</artifactId>
            <version>4.0.10</version>
            <configuration>
                <pactDirectory>target/pacts</pactDirectory>
                <pactBrokerUrl>http://pact-broker-hmh.devel.hmheng-qe.brnp.internal/</pactBrokerUrl>
                <projectVersion>${project.version}</projectVersion>
                <trimSnapshot>true</trimSnapshot>
            </configuration>
        </plugin>
    </plugins>
</build>

这就是我在 运行ning maven 依赖树之后寻找 Kotlin 时所看到的。可以找到完整的项目 here.

非常感谢。

您遇到该错误的一个可能原因(我假设)是因为您正在混合主要版本的 Pact 库。

<pact.version>3.5.24</pact.version>
<pact-jvm-provider-maven.version>3.5.9</pact-jvm-provider-maven.version>
<pact-jvm-maven.version>3.5.24</pact-jvm-maven.version>
<pact.jvm.consumer.junit.version>4.0.10</pact.jvm.consumer.junit.version>

您有 3.5.9、3.5.24 和 4.0.10 版本。您应该使用相同的主要版本。

版本 3.5.x 大部分是用 Kotlin 编写的(可能是版本 1.2.x),而版本 4.0.x 是使用 Kotlin 1.3.x 编写的.

我不确定为什么 Sprinboot 会产生影响,但也许 Spring 依赖项也引入了 Kotlin 标准库的一个版本。

最好的办法是对所有 Pact 库使用版本 4.0.10,然后 运行 Maven 依赖树插件并检查正在使用的 Kotlin 标准库的版本。