【问题标题】:How to upload the stub.jar generated by spring cloud contractspring cloud合约生成的stub.jar如何上传
【发布时间】:2018-11-07 22:36:36
【问题描述】:

我一直在使用 Spring Cloud Contract 来测试 Producer Side。现在,我想将 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. 在 pom 中添加“skip”行后,我发现 stubs json 永远不会生成。
  2. 我使用的是 Spring Cloud Contract 1.2.4,我认为目标中只有“stub”文件夹,而不是“sn-ps/stubs”。
  3. stub.jar 中需要哪些文件才能运行 Stub Runner?

【问题讨论】:

    标签: spring-cloud spring-cloud-contract


    【解决方案1】:

    我一直在使用 Spring Cloud Contract 来测试 Producer Side。现在,我想将 stub.jar 文件上传到 nexus,这样我的同事就可以针对我的制作人编写一些集成测试。

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

    我发现 Spring 文档很难遵循。

    这不是很具体吗?究竟是什么难以理解?

    在 pom 中添加“skip”行后,我发现 stubs json 永远不会生成。

    skip 哪一行?如果您添加 &lt;spring.cloud.contract.verifier.jar.skip&gt;false&lt;/spring.cloud.contract.verifier.jar.skip&gt;,那么我们将仅禁用 JAR 创建。

    我使用的是 Spring Cloud Contract 1.2.4,我认为目标中只有“stub”文件夹,而不是“sn-ps/stubs”。

    你还在使用 Rest Docs 吗?你从哪里得到的sn-p?从这里https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_publishing_stubs_as_jars ?如果您通过 sn-p 阅读文本,您将看到 For both Maven and Gradle, the setup comes ready to work. However, you can customize it if you want to.。如果您按照文档的分步部分进行操作,我们将描述整个最基本的流程。还有多个教程,包括一个非常详尽的教程http://cloud-samples.spring.io/spring-cloud-contract-samples/workshops.html

    stub.jar 中需要哪些文件才能让 Stub Runner 运行它?

    我们在文档中对此进行了描述。如果您想使用类路径映射,请阅读此部分 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。我认为您应该从头开始阅读文档并按照教程进行操作。或者告诉我们文档中有哪些不清楚的地方让您感到困惑。

    【讨论】:

    • 感谢@Marcin Grzejszczak 的详细回答。在浏览了您提供的参考资料后,我明白了为什么我对文档感到困惑。当我只想将存根上传到 nexus 时,我会直接转到文档的 Section 6。程序集文件 stub.xml 用于使用 Rest Docs 的项目,我在项目中没有使用它。所以没有生成json文件,也没有sn-ps/json路径。
    猜你喜欢
    • 2018-06-09
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多