【问题标题】:Spring cloud contract stubs not found in my local repo在我的本地仓库中找不到 Spring Cloud 合约存根
【发布时间】:2017-01-17 04:29:52
【问题描述】:

使用 Spring Cloud Contract 1.0.2.RELEASE,我可以在本地 Maven 存储库中发布存根,但是当我运行测试时,消费者端找不到它们。

看起来在消费者方面,它为本地 maven 存储库选择了与生产者不同的位置:尽管 Spring Cloud Contract 和 Aether 库的日志记录很好,但我花了一段时间才弄清楚,作为位置我用于本地 Maven 存储库与默认存储库相似(但不同)。

我正在使用 Maven 3.3.1。

【问题讨论】:

    标签: java maven-3 spring-cloud-contract


    【解决方案1】:

    在 org.springframework.cloud.contract.stubrunner.AetherFactories 中,我们清楚地看到它像这样获取本地存储库位置:

    private static final String MAVEN_LOCAL_REPOSITORY_LOCATION = "maven.repo.local";
    
    private static String localRepositoryDirectory() {
        return System.getProperty(MAVEN_LOCAL_REPOSITORY_LOCATION, System.getProperty("user.home") + "/.m2/repository");
    }
    

    因此,如果您使用以下内容覆盖 Maven settings.xml 中的本地 Maven 存储库位置:

    <localRepository>C:/HOMEWARE/maven_local_repo</localRepository>
    

    您的生产者将在此位置安装存根,但消费者将在默认位置查找本地存储库,除非您通过“maven.repo.local”系统属性定义自己的位置

    你可以在消费者端使用surefire来做到这一点:

    <build>
        ...
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <maven.repo.local>${settings.localRepository}</maven.repo.local>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    【讨论】:

    • 感谢您的解释,我认为 Spring Cloud Contracts 应该默认搜索 ~/.m2/reposiroty 中的存根,not 根据 maven.repo.local 设置,但如果我没有设置 /${user.home}/.m2/repository ,它似乎在我的项目中搜索 b>maven.repo.local.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 2019-08-26
    • 2018-02-25
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多