该工件在本地存储库中找到,但您已明确声明应从远程存储库下载它”

The artifact was found in the local repository but you have explicitly stated that it should be downloaded from a remote one"

我有一个消费者项目,它有 spring 云合同测试验证器,它需要与远程仓库中的存根 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 对话。

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

91.4 CI Server setup

When fetching stubs / contracts in a CI, shared environment, what might happen is that both the producer and the consumer reuse the same local Maven repository. Due to this, the framework, responsible for downloading a stub JAR from remote location, can’t decide which JAR should be picked, local or remote one. That caused the "The artifact was found in the local repository but you have explicitly stated that it should be downloaded from a remote one" exception and failed the build.

For such cases we’re introducing the property and plugin setup mechanism:

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

if either of these values is set to true, then the stub downloader will not verify the origin of the downloaded JAR.

For the plugins you need to set the contractsSnapshotCheckSkip property to true.

只要按照文档中的指导进行操作,您就不会再遇到这个问题了。或者碰上格林威治发布列车,这个问题得到了完全解决。