Spring Cloud Contract issues retrieving stubs from Artifactory

时光毁灭记忆、已成空白 提交于 2019-12-05 21:36:58

I have looked in Artifactory and in https://artifactory.mycompany.com/artifactory/artifacts-snapshot-local and the stubs jar appears there. I have done a mvn install of the producer and when I run the tests again I get this error "The artifact was found in the local repository but you have explicitly stated that it should be downloaded from a remote one".

This happens when you install a stub locally, then try to download it from artifactory but SHAs are different, so Aether (engine that downloads stubs) picks the local one. In this case we throw an exception cause you wanted to download the stub from a remote location and not take it from the local one.

Exception occurred while trying to download a stub for group [com.mycompany] module [service-name] and classifier [stubs] in [remote0 (https://artifactory.mycompany.com/artifactory/artifacts-snapshot-local, default, releases+snapshots)] org.eclipse.aether.resolution.ArtifactResolutionException: Could not find artifact com.mycompany.domain:service-name:jar:stubs:1.6.0-SNAPSHOT

This looks like in Artifactory you had the entry in some Maven metadata that the latest jar is 1.6.0-SNAPSHOT but the JAR is no longer there. Can you double check that it's actually there?

I have also tried adding to the consumers a dependency on the stubs of the producer but I get similar errors. And I would prefer to avoid it because it would add a dependency with the specific version of the producer:

That only proves that you have something messed up with your artifactory / project settings. Do things still don't work if you hardcode versions?

UPDATE:

If your artifactory instance requires credentials or is behind a proxy you can use these values:

https://github.com/spring-cloud/spring-cloud-contract/blob/v1.1.4.RELEASE/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java#L72-L87

You can provide the stubrunner.username, stubrunner.password, stubrunner.proxyHost and stubrunner.proxyPort

Can stubrunner.username and stubrunner.password be provided in the @AutoConfigureStubRunner annotation? I have tried the following:

 @RunWith(SpringRunner.class)
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
 @AutoConfigureStubRunner(ids = "com.mycompany.myproj:myservice:+:stubs:8100",
    repositoryRoot = "http://artifactory.mycompany.com/artifactory/libs-snapshot-local",
    properties = {"stubrunner.username=myusername", "stubrunner.password=mypassword"},
    stubsMode = StubRunnerProperties.StubsMode.REMOTE)
 @DirtiesContext
 class MyApiContractsVerificationTest {
     ...
 }

The credentials are correct, and the stubs are correctly generated and deployed into the remote Artifactory repository. The tests run fine if I configure them to look in the local .m2/repository (removing the "repositoryRoot and "properties" annotation args), but with the above configuration I get the following error:

Could not find metadata com.mycommany.myproject:myservice/maven-metadata.xml in local (/Users/myname/.m2/repository), 
org.eclipse.aether.transfer.MetadataTransferException: Could not transfer metadata com.mycommany.myproject:myservice/maven-metadata.xml from/to remote0 (http://artifactory.mycompany.com/artifactory/libs-snapshot-local): **Unauthorized (401)**]
...

I do clean the local .m2/repository of the stubs before I run the tests with the remote mode enabled, so there is no conflict.

Am I incorrectly providing the username and password? Is something incorrect or missing in the configuration?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!