W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
使用SCM作為存根和合同目的地的另一種選擇是與生產(chǎn)者一起在本地存儲合同,并且僅將合同和存根推送到SCM。在下面,您可以找到使用Maven和Gradle完成此操作所需的設(shè)置。
Maven.
<plugin> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-maven-plugin</artifactId> <version>${spring-cloud-contract.version}</version> <extensions>true</extensions> <!-- In the default configuration, we want to use the contracts stored locally --> <configuration> <baseClassMappings> <baseClassMapping> <contractPackageRegex>.*messaging.*</contractPackageRegex> <baseClassFQN>com.example.BeerMessagingBase</baseClassFQN> </baseClassMapping> <baseClassMapping> <contractPackageRegex>.*rest.*</contractPackageRegex> <baseClassFQN>com.example.BeerRestBase</baseClassFQN> </baseClassMapping> </baseClassMappings> <basePackageForTests>com.example</basePackageForTests> </configuration> <executions> <execution> <phase>package</phase> <goals> <!-- By default we will not push the stubs back to SCM, you have to explicitly add it as a goal --> <goal>pushStubsToScm</goal> </goals> <configuration> <!-- We want to pick contracts from a Git repository --> <contractsRepositoryUrl>git://file://${env.ROOT}/target/contract_empty_git/ </contractsRepositoryUrl> <!-- Example of URL via git protocol --> <!--<contractsRepositoryUrl>git://git@github.com:spring-cloud-samples/spring-cloud-contract-samples.git</contractsRepositoryUrl>--> <!-- Example of URL via http protocol --> <!--<contractsRepositoryUrl>git://https://github.com/spring-cloud-samples/spring-cloud-contract-samples.git</contractsRepositoryUrl>--> <!-- We reuse the contract dependency section to set up the path to the folder that contains the contract definitions. In our case the path will be /groupId/artifactId/version/contracts --> <contractDependency> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> </contractDependency> <!-- The mode can't be classpath --> <contractsMode>LOCAL</contractsMode> </configuration> </execution> </executions> </plugin>
Gradle.
contracts { // Base package for generated tests basePackageForTests = "com.example" baseClassMappings { baseClassMapping(".*messaging.*", "com.example.BeerMessagingBase") baseClassMapping(".*rest.*", "com.example.BeerRestBase") } } /* In this scenario we want to publish stubs to SCM whenever the `publish` task is executed */ publishStubsToScm { // We want to modify the default set up of the plugin when publish stubs to scm is called customize { // We want to pick contracts from a Git repository contractDependency { stringNotation = "${project.group}:${project.name}:${project.version}" } /* We reuse the contract dependency section to set up the path to the folder that contains the contract definitions. In our case the path will be /groupId/artifactId/version/contracts */ contractRepository { repositoryUrl = "git://file://${System.getenv("ROOT")}/target/contract_empty_git/" } // The mode can't be classpath contractsMode = "LOCAL" } } publish.dependsOn("publishStubsToScm") publishToMavenLocal.dependsOn("publishStubsToScm")
通過這樣的設(shè)置:
src/test/resources/contracts
目錄中選擇Contracts一旦測試通過
origin
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: