简体   繁体   English

使用maven时Spring Cloud Contract编译问题

[英]Spring Cloud Contract compilation problems when using maven

I recently added spring cloud contract to our spring project following the instructions on their tutorial site here ( https://cloud.spring.io/spring-cloud-contract/#quick-start ).我最近按照他们的教程站点( https://cloud.spring.io/spring-cloud-contract/#quick-start )上的说明将 spring cloud contract 添加到我们的 spring 项目中。

I managed to write contracts, generate stubs and everything works as expected, but I have a problem when working with a clean project after pulling it off our repository.我设法编写了合同,生成了存根,一切都按预期工作,但是在将一个干净的项目从我们的存储库中拉出来后,我在处理一个干净的项目时遇到了问题。 When I let mvn test run I get compilation errors in the generated test-class because it seems like the project itself didn't build before so the base-class for the contract tests on the producer site doesn't seem to exist yet.当我让mvn test运行时,我在生成的测试类中遇到编译错误,因为项目本身之前似乎没有构建,因此生产者站点上的合同测试的基类似乎还不存在。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project kongo-shoppingcart-service: Compilation failure: Compilation failure: [ERROR] [...]/src/kongo-service-shoppingcart/kongo-shoppingcart-service/target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java:[7,64] package edu.hm.ba.kongo.shop.shoppingcart.service.test.contracts does not exist [ERROR] [...]/src/kongo-service-shoppingcart/kongo-shoppingcart-service/target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java:[14,43] cannot find symbol [ERROR] symbol: class ContractTestBase

My projects pom looks like this:我的项目 pom 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>Brixton.M5</version>
    <relativePath/>
</parent>

<groupId>edu.hm.ba.kongo.shop</groupId>
<artifactId>kongo-shoppingcart-service</artifactId>
<name>kongo :: shoppingcart :: service</name>
<version>1.0</version>

<properties>
    <java.version>1.8</java.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
    <!-- Spring Boot -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</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-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.plugin</groupId>
        <artifactId>spring-plugin-core</artifactId>
    </dependency>
    <!-- Spring Boot -->

    <!-- Spring Data -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-rest-hal-browser</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
    </dependency>
    <!-- Spring Data -->

    <!-- Spring Cloud -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-ribbon</artifactId>
    </dependency>
    <!-- Spring Cloud -->

    <!-- json usw. -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <version>2.7.1</version>
    </dependency>
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path</artifactId>
    </dependency>
    <!-- json usw. -->

    <!-- Datenbank -->
    <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search-orm</artifactId>
        <version>5.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <!-- Datenbank -->

    <!-- Validation -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.3.1.Final</version>
    </dependency>
    <!-- Validation -->

    <!-- Other -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
    </dependency>
    <!-- test -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.6.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-contract-verifier</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- internal -->
    <dependency>
        <groupId>de.muenchen</groupId>
        <artifactId>Service-Lib</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>de.muenchen</groupId>
        <artifactId>Auditing</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-dependencies</artifactId>
            <version>1.0.3.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <artifactId>spring-data-rest-webmvc</artifactId>
            <groupId>org.springframework.data</groupId>
            <version>2.5.0.RELEASE</version>
        </dependency>
        <dependency>
            <artifactId>spring-data-rest-core</artifactId>
            <groupId>org.springframework.data</groupId>
            <version>2.5.0.RELEASE</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/docker</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>0.4.13</version>
                    <configuration>
                        <imageName>${project.artifactId}</imageName>
                        <dockerDirectory>target</dockerDirectory>
                        <resources>
                            <resource>
                                <targetPath>/</targetPath>
                                <directory>${project.build.directory}</directory>
                                <include>${project.build.finalName}.jar</include>
                            </resource>
                        </resources>
                    </configuration>
                    <!-- Uncomment if you want to build a new image for every 'mvn package'
                    <executions>
                        <execution>
                            <id>build-image</id>
                            <phase>package</phase>
                            <goals>
                                <goal>build</goal>
                            </goals>
                        </execution>
                    </executions>
                    -->
                </plugin>
        <plugin>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-maven-plugin</artifactId>
            <version>1.0.3.RELEASE</version>
            <!-- Don't forget about this value !! -->
            <extensions>true</extensions>
            <configuration>
                <baseClassForTests>edu.hm.ba.kongo.shop.shoppingcart.service.test.contracts.ContractTestBase</baseClassForTests>
                <contractsDirectory>src/main/test/edu/hm/ba/kongo/shop/shoppingcart/service/test/contracts</contractsDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

But when I build the module by hand and run mvn test afterwords everything works as expected.但是当我手动构建模块并运行mvn test afterwords 时,一切都按预期工作。 Is there something wrong with the declaration of my POM?我的 POM 的声明有什么问题吗?

For some reason your project can't see your base test class.出于某种原因,您的项目看不到您的基础测试类。 It's not on the classpath.它不在类路径上。 Are you sure you placed it in a proper folder?你确定你把它放在正确的文件夹中吗? You'd have to show your folder structure.你必须显示你的文件夹结构。 Also you can check out https://github.com/spring-cloud-samples/spring-cloud-contract-samples and do sth similar.你也可以查看https://github.com/spring-cloud-samples/spring-cloud-contract-samples并做类似的事情。 BTW src/main/test looks really bad so most likely your project setup is wrong.顺便说一句src/main/test看起来很糟糕,所以很可能你的项目设置是错误的。 I'd suggest keeping the contracts and the base classes under src/test/resources and src/test/java respectively我建议将合同和基类分别放在src/test/resourcessrc/test/java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用spring-cloud-contract-oa3和spring cloud contract gradle插件时无法生成合约测试 - Unable to generate contract tests when using spring-cloud-contract-oa3 and spring cloud contract gradle plugin Spring Cloud Contract 测试适用于 Maven,但不适用于 JUnit - Spring Cloud Contract tests work with Maven but not when run with JUnit 使用Spring Cloud和Spring Boot 2.0.1时Maven依赖项不兼容 - Maven dependencies incompatibility when using spring cloud and spring boot 2.0.1 如何通过Spring Cloud Contract Verifier跳过测试生成Maven目标? - How to skip the test generation maven goal with Spring Cloud Contract Verifier? Maven 构建失败,Spring-cloud-contract-verifier - Maven build fails with Spring-cloud-contract-verifier Spring Cloud合约测试的在线/离线模式存在问题 - Problems with the online / offline mode of the Spring Cloud contract tests 使用Spring Boot与Cassandra的Maven编译错误 - Maven Compilation Error using Spring Boot with Cassandra 做spring cloud合约测试时找不到@SpringBootConfiguration - Unable to find a @SpringBootConfiguration when doing spring cloud contract test 使用Maven引用库时出现编译错误 - compilation error when referring to a library using maven 春季云合同-假客户 - spring cloud contract - Feign Clients
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM