如何上传 stub.jar 生成的 spring 云合约

How to upload the stub.jar generated by spring cloud contract

我一直在使用 Spring Cloud Contract 来测试生产者端。现在,我想将 stub.jar 文件上传到 nexus,这样我的同事就可以针对我的生产者编写一些集成测试。我发现 Spring 文档很难理解。

    <!-- First disable the default jar setup in the properties section-->
    <!-- we don't want the verifier to do a jar for us --> 
    <spring.cloud.contract.verifier.skip>true</spring.cloud.contract.verifier.skip> 

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>stubs</id>
<formats>
    <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
    <fileSet>
        <directory>src/main/java</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**com/example/model/*.*</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}/classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**com/example/model/*.*</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}/snippets/stubs</directory>
        <outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings</outputDirectory>
        <includes>
            <include>**/*</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>${basedir}/src/test/resources/contracts</directory>
        <outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/contracts</outputDirectory>
        <includes>
            <include>**/*.groovy</include>
        </includes>
    </fileSet>
</fileSets>

  1. 将 "skip" 行添加到 pom 后,我发现存根 json 永远不会生成。
  2. 我正在使用 Spring Cloud Contract 1.2.4,我认为目标中只有 "stub" 文件夹,而不是 "snippets/stubs"。
  3. Stub Runner stub.jar 中需要哪些文件才能运行?

I've been using Spring Cloud Contract to test the Producer Side. And now, I wanted to upload the stub.jar file to nexus, so my colleague could write some integration test against my producer.

如果您使用 DSL,则无需执行任何操作。只需执行 ./mvnw deploy,我们将生成 fat jar 和 stubs jar。

And I found the Spring Documentation hard to follow.

这不是很具体,是吗?究竟什么是难以遵循的?

After I add the "skip" line to the pom, I found that stubs json never get generated.

skip行?如果您添加 <spring.cloud.contract.verifier.jar.skip>false</spring.cloud.contract.verifier.jar.skip> 那么我们将仅禁用 JAR 创建。

I'm using Spring Cloud Contract 1.2.4, and I think there is only "stub" folder in the target, not a "snippets/stubs".

您还在使用 Rest Docs 吗?你从哪里得到的片段?从这里 https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_publishing_stubs_as_jars ? If you read the text over the snippet you'll see For both Maven and Gradle, the setup comes ready to work. However, you can customize it if you want to.. If you follow the step by step section of the documentation we describe the whole, most basic flow. Also there are multiple tutorials out there, including a very thorough one over here http://cloud-samples.spring.io/spring-cloud-contract-samples/workshops.html

What files are required in the stub.jar for the Stub Runner to run it?

我们在文档中对此进行了描述。如果您想使用类路径映射,请阅读本节 https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_classpath_scanning。否则,我们解压并浏览我们可以解析的任何 WireMock Json 文件。

这里有一个手动创建存根 jar 的工作示例 - https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/master/producer_with_restdocs。我认为您应该从头开始阅读文档并按照教程进行操作。或者告诉我们文档中到底有什么地方不清楚让您感到困惑。