Java Maven构建使用Spring云契约验证程序失败

Java Maven构建使用Spring云契约验证程序失败,java,spring,maven,spring-boot,spring-cloud-contract,Java,Spring,Maven,Spring Boot,Spring Cloud Contract,我在使用以下pom.xml构建spring云合同验证程序时遇到问题: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath /

我在使用以下pom.xml构建
spring云合同验证程序时遇到问题:

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <docker-maven-plugin.version>1.2.0</docker-maven-plugin.version>
        <spring-cloud.version>1.3.2.RELEASE</spring-cloud.version>
        <geometry.version>2.11</geometry.version>
        <mockito.version>1.9.5</mockito.version>
    </properties>

    <dependencies>

        <!--############################################# SPRING ####################################################-->

        <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-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.ehcache</groupId>
            <artifactId>ehcache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>5.0.12.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.cache</groupId>
            <artifactId>cache-api</artifactId>
        </dependency>

        <!--######################################### SPRING-CLOUD ##################################################-->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-contract-verifier</artifactId>
            <version>2.1.1.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-test-support</artifactId>
            <version>1.3.3.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>spring-mock-mvc</artifactId>
            <version>2.2.0</version>
            <scope>test</scope>
        </dependency>

        <!--############################################## MYSQL ####################################################-->

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!--############################################### GEO #####################################################-->

        <dependency>
            <groupId>com.jillesvangurp</groupId>
            <artifactId>geogeometry</artifactId>
            <version>${geometry.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--############################################ MOCKITO ####################################################-->

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <!--##################################### END-OF-DEPENDENCIES ###############################################-->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-contract-maven-plugin</artifactId>
                <version>1.2.2.RELEASE</version>
                <extensions>true</extensions>
                <configuration>
                    <baseClassForTests>
                        com.foo.pricing.contract.BaseClass
                    </baseClassForTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
我偶然发现的例外情况如下:

[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ PricingService ---
[INFO] 
[INFO] --- spring-cloud-contract-maven-plugin:1.2.2.RELEASE:generateStubs (default-generateStubs) @ PricingService ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.079 s
[INFO] Finished at: 2019-03-13T16:09:17+03:30
[INFO] Final Memory: 62M/483M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.cloud:spring-cloud-contract-maven-plugin:1.2.2.RELEASE:generateStubs (default-generateStubs) on project PricingService: Stubs could not be found: [/home/akarimin/project/foo/pricing-service/pricing/target/stubs] .
[ERROR] Please make sure that spring-cloud-contract:convert was invoked
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

如果您能帮助我解决这个问题,我将不胜感激。

看来您在默认路径(src/test/resources/contracts)下没有任何契约,这会导致不复制到目标,从而导致异常。

经过几天的努力寻找解决方案,我得出结论,我的Spring引导版本(1.5.10)与SpringCloudContractVerifier(2.1.1)不兼容,尽管我没有在web上找到任何兼容性矩阵,它只是基于我在本例中的实验。通过迁移到SpringBoot2.1.x,这个问题得到了解决,它的工作非常出色。非常感谢Josh Long和Marcin Grzejszczak在春季合同会议上的介绍


要对问题应用临时解决方案,只需在(
src/test/resources
下创建一个文件夹contracts即可。创建后,它应该是(
src/test/resources/contracts
)。
但是您应该实现契约验证器,以相应地满足您的端点。我希望这能有所帮助。

谢谢你的回答。实际上,我的合同就在这条路径下。问题解决了,所以我解释了我的问题和解决方法。查看SpringCloud主页的兼容性矩阵-。我们也在博客上发布了新版本,其中提到了启动兼容性——当然,我会的,非常感谢。
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ PricingService ---
[INFO] 
[INFO] --- spring-cloud-contract-maven-plugin:1.2.2.RELEASE:generateStubs (default-generateStubs) @ PricingService ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.079 s
[INFO] Finished at: 2019-03-13T16:09:17+03:30
[INFO] Final Memory: 62M/483M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.cloud:spring-cloud-contract-maven-plugin:1.2.2.RELEASE:generateStubs (default-generateStubs) on project PricingService: Stubs could not be found: [/home/akarimin/project/foo/pricing-service/pricing/target/stubs] .
[ERROR] Please make sure that spring-cloud-contract:convert was invoked
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException