【问题标题】:Cannot find ContractVerifierUtil class while trying to generate spring cloud contracts尝试生成 Spring Cloud 合约时找不到 ContractVerifierUtil 类
【发布时间】:2020-11-16 08:56:18
【问题描述】:

我正在尝试为我的 API 生成云合同,但构建失败,因为生成的测试类无法从依赖项中找到以下类。

 Compilation failure--import static org.springframework.cloud.contract.verifier.util.ContractVerifierUtil.*;

[ERROR] ContractVerifierTest.java:[18,63] cannot find symbol
[ERROR]   symbol:   class ContractVerifierUtil
[ERROR]   location: package org.springframework.cloud.contract.verifier.util

这些是我在 pom.xml 中的依赖项

    <dependency>
        <groupId>com.atlassian.oai</groupId>
        <artifactId>swagger-request-validator-mockmvc</artifactId>
        <version>2.10.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.3.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-contract-verifier</artifactId>
        <version>2.2.3.RELEASE</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Hoxton.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>

和我的 maven 插件配置

       <plugin>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-maven-plugin</artifactId>
            <version>2.1.1.RELEASE</version>
            <extensions>true</extensions>
            <configuration>
                <baseClassForTests>
                    com.test.specValidation.ContractTest
                </baseClassForTests>
            </configuration>
        </plugin>

我看过类似的 post,但版本看起来与 spring cloud docs 兼容

Table 1. Release train Spring Boot compatibility
Release Train   Boot Version
Hoxton

2.2.x

我尝试了多个版本,但似乎都不起作用。关于我所缺少的任何指导?

【问题讨论】:

    标签: java spring spring-cloud maven-plugin spring-cloud-contract


    【解决方案1】:

    请使插件的版本与合约依赖的版本保持一致。您在 2.2.3.RELEASE 版本中使用验证程序,但插件在 2.1.1.RELEASE 中。它们必须在同一版本中使用。

    【讨论】:

    • 我试过用同一个版本的插件和verifier..帮助不大
    • 您的版本不匹配。当您以 2 个不同版本导入合同时,这是一个已知问题。插件在新版本中,在旧版本中测试编译类路径
    • 是的,我已经在插件和依赖项上尝试了 2.2.3.RELEASE 版本,但它并没有帮助解决问题。谢谢你的信息
    • 把你的发布火车也撞了。为什么要手动设置 hoxton 和云项目版本。他们将从 bom 解决
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多