I have consumer project, which has spring cloud contract tests verifier,which needs to talk to the stubs jar in the remote repo. The setup for stubsMode: LOCAL works fine, but for remote it throws the following error.
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
Consumer Side remote code:
`@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>
I need to use REMOTE repoUrl for the consumer project to talk to the producer stub jar.
If you read the documentation at this section https://cloud.spring.io/spring-cloud-static/Finchley.SR2/single/spring-cloud.html#_ci_server_setup (it's actually enough to find the exception you were looking for in the documentation) you'll see the following text:
Just follow the guidelines from the documentation and you won't have this problem anymore. Or bump to Greenwich release train where this issue got completely fixed.