0

我有消费者项目,它有弹簧云合同测试验证器,它需要与远程仓库中的存根 jar 对话。的设置stubsMode: LOCAL工作正常,但对于远程它会引发以下错误。

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.contract.stubrunner.BatchStubRunner]: Factory method 'batchStubRunner' threw exception; nested exception is java.lang.IllegalStateException: The artifact was found in the local repository but you have explicitly stated that it should be downloaded from a remote one
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
    ... 43 more
Caused by: java.lang.IllegalStateException: The artifact was found in the local repository but you have explicitly stated that it should be downloaded from a remote one

消费者端远程代码:

`@RunWith(SpringRunner.class)
@SpringBootTest(classes = RestClientConfig.class,
        webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureStubRunner(   repositoryRoot="https://nexus.com/nexus/content/repositories/sam-releases/com/sam/api/",
        ids = "com.sam:api:+:stubs:8083",
        stubsMode = StubRunnerProperties.StubsMode.REMOTE
)

pom.xml

<spring-cloud.version>Finchley.SR2</spring-cloud.version>
    <spring-cloud-contract.version>2.0.2.RELEASE</spring-cloud-contract-version>

我需要使用 REMOTE repoUrl 让消费者项目与生产者存根 jar 对话。

4

1 回答 1

2

如果您阅读本节中的文档https://cloud.spring.io/spring-cloud-static/Finchley.SR2/single/spring-cloud.html#_ci_server_setup(实际上足以找到您正在寻找的异常文档)您将看到以下文本:

91.4 CI 服务器设置

在 CI 共享环境中获取存根/合约时,可能发生的情况是生产者和消费者都重用相同的本地 Maven 存储库。因此,负责从远程位置下载存根 JAR 的框架无法决定应该选择哪个 JAR,本地的还是远程的。这导致了“在本地存储库中找到了工件,但您已明确声明应该从远程存储库下载它”异常并且构建失败。

对于这种情况,我们将引入属性和插件设置机制:

via stubrunner.snapshot-check-skip system property
via STUBRUNNER_SNAPSHOT_CHECK_SKIP environment variable

如果这些值中的任何一个设置为 true,则存根下载器将不会验证下载 JAR 的来源。

对于插件,您需要将contractsSnapshotCheckSkip 属性设置为true。

只需遵循文档中的指南,您就不会再遇到这个问题了。或者撞到格林威治发布火车,这个问题得到了完全解决。

于 2019-05-08T11:48:50.677 回答