Publish Spring Cloud Contract verification to Pact broker

♀尐吖头ヾ 提交于 2021-02-11 13:10:34

问题


Is it possible to publish Spring Cloud Contract Producer verification to a Pact broker?


回答1:


You would have to convert the DSL to Pact files and then push those. So technically that is possible.

Update: We describe how to do this in the documentation - https://cloud.spring.io/spring-cloud-contract/reference/html/howto.html#how-to-generate-pact-from-scc

Since in SO it seems that an answer "Check the docs" is not an accepted one, let me just copy paste the documentation

  1. How Can I Generate Pact, YAML, or X files from Spring Cloud Contract Contracts?

Spring Cloud Contract comes with a ToFileContractsTransformer class that lets you dump contracts as files for the given ContractConverter. It contains a static void main method that lets you execute the transformer as an executable. It takes the following arguments:

argument 1 : FQN: Fully qualified name of the ContractConverter (for example, PactContractConverter). REQUIRED.

argument 2 : path: Path where the dumped files should be stored. OPTIONAL — defaults to target/converted-contracts.

argument 3 : path: Path were the contracts should be searched for. OPTIONAL — defaults to src/test/resources/contracts.

After executing the transformer, the Spring Cloud Contract files are processed and, depending on the provided FQN of the ContractTransformer, the contracts are transformed to the required format and dumped to the provided folder.

The following example shows how to configure Pact integration for both Maven and Gradle:

maven

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
        <execution>
            <id>convert-dsl-to-pact</id>
            <phase>process-test-classes</phase>
            <configuration>
                <classpathScope>test</classpathScope>
                <mainClass>
                    org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer
                </mainClass>
                <arguments>
                    <argument>
                        org.springframework.cloud.contract.verifier.spec.pact.PactContractConverter
                    </argument>
                    <argument>${project.basedir}/target/pacts</argument>
                    <argument>
                        ${project.basedir}/src/test/resources/contracts
                    </argument>
                </arguments>
            </configuration>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

gradle

task convertContracts(type: JavaExec) {
    main = "org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer"
    classpath = sourceSets.test.compileClasspath
    args("org.springframework.cloud.contract.verifier.spec.pact.PactContractConverter",
            "${project.rootDir}/build/pacts", "${project.rootDir}/src/test/resources/contracts")
}

test.dependsOn("convertContracts")

After having the files generated at build/pacts or target/pacts you can use the Pact Gradle / Maven plugin to upload those files to the broker.



来源:https://stackoverflow.com/questions/52779248/publish-spring-cloud-contract-verification-to-pact-broker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!