微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Spring Cloud Contract Stub Runner 并在一个地方应用程序从合同放置在 git 中的合同生成存根

如何解决使用 Spring Cloud Contract Stub Runner 并在一个地方应用程序从合同放置在 git 中的合同生成存根

有可能吗? 我想为烟雾测试创建存根服务器:

  1. 在构建时,它从 git 存储库中获取多个 REST 应用程序的合约,构建存根并将它们作为 jsons 推送回存储库
  2. 在启动时,它从存储库中获取存根 jsons 并运行它们

我试过了:

主类:

@SpringBootApplication
@EnableStubRunnerServer
public class SpringCloudStubRunnerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudStubRunnerApplication.class,args);
    }

}

application.yaml:

server:
  port: 8080

stubrunner:
  stubsMode: REMOTE
  repositoryRoot: git://git@github.com:Granomir/spring-cloud-config-stubs.git
  ids:
    - ru.mts.poisk:my-content-adapter:+:stubs:8090

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/>
    </parent>
    <groupId>ru.mts.poisk</groupId>
    <artifactId>spring-cloud-stub-runner</artifactId>
    <version>1.0-S1-SNAPSHOT</version>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-stub-runner</artifactId>
            <version>2.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-contract-verifier</artifactId>
            <version>2.2.6.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-contract-maven-plugin</artifactId>
                <version>2.2.6.RELEASE</version>
                <extensions>true</extensions>
                <configuration>
                    <contractsRepositoryUrl>git://git@github.com:Granomir/spring-cloud-config-stubs.git</contractsRepositoryUrl>
                    <contractDependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>my-content-adapter</artifactId>
                        <version>${project.version}</version>
                    </contractDependency>
                    <contractsMode>REMOTE</contractsMode>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>pushStubsToScm</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

当我使用 'mvn clean install -DskipTests' 生成存根时,日志中的内容如下:

[INFO] Pattern to pick contracts equals [^/tmp/git-contracts-1614681706091-0/meta-inf/ru.mts.poisk/my-content-adapter/1.0-S1-SNAPSHOT(/)?.*ru/mts/poisk/spring-cloud-stub-runner/.*$]
[INFO] Ant Pattern to pick files equals [**/ru/mts/poisk/spring-cloud-stub-runner/**/]

所以我的应用程序不会生成存根并且没有什么可推回的,因为我在 git 中有另一个目录结构

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。