Spring Cloud Contract问题从Artifactory检索存根 [英] Spring Cloud Contract issues retrieving stubs from Artifactory

查看:104
本文介绍了Spring Cloud Contract问题从Artifactory检索存根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个消费者的测试,一个生产者可以脱机工作,但是当我为从Artifactory检索存根而更改它们时,消费者测试失败.

I have tests for two consumers and a producer working fine offline but the consumer tests fail when I change them for retrieving the stubs from Artifactory.

这是离线工作的代码:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ContractTestConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = {"com.mycompany:service-name:+:stubs"}, workOffline = true)
@ImportAutoConfiguration(org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration.class)
@DirtiesContext
public class MyContractTest

这是在线上的

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ContractTestConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = {"com.mycompany:service-name:+:stubs"}, repositoryRoot = "https://artifactory.companyname.com/artifactory/artifacts-snapshot-local")
@ImportAutoConfiguration(org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration.class)
@DirtiesContext
public class MyContractTest {

我收到此错误:

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

我看过Artifactory和 https://artifactory.mycompany.com/artifactory/artifacts-snapshot-local ,并且存根jar出现在此处.我已经完成了生产器的mvn安装,并且当我再次运行测试时,我收到此错误在本地存储库中找到了工件,但您已经明确声明应从远程对象中下载该工件".

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".

我也曾尝试向消费者添加对生产者存根的依赖,但是我遇到类似的错误.而且我宁愿避免这种情况,因为它会添加特定于生产者版本的依赖项:

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:

<dependency>
    <groupId>com.companyname</groupId>
    <artifactId>service-name</artifactId>
    <classifier>stubs</classifier>
    <version>1.6.0-SNAPSHOT</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

我已将其添加到生产者的POM文件中:

I have added this to the POM file of the producer:

<spring.cloud.contract.verifier.skip>true</spring.cloud.contract.verifier.skip>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <id>stub</id>
            <goals>
                <goal>single</goal>
            </goals>
            <phase>prepare-package</phase>
            <inherited>false</inherited>
            <configuration>
                <attach>true</attach>
                <descriptor>${basedir}/src/assembly/stub.xml</descriptor>
            </configuration>
        </execution>
    </executions>
</plugin>

这是src/assembly下的stub.xml文件的内容:

And this is the content of the file stub.xml that is under src/assembly:

<assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>stubs</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/java</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>**com/companyname/projectname/*.*</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}/classes</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>**com/companyname/projectname/*.*</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}/snippets/stubs</directory>
            <outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings</outputDirectory>
            <includes>
                <include>**/*</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${basedir}/src/test/resources/contracts</directory>
            <outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/contracts</outputDirectory>
            <includes>
                <include>**/*.groovy</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

对我所缺少的东西有任何想法吗?预先感谢

Any idea of what I am missing? Thanks in advance

推荐答案

我看过Artifactory和 https://artifactory.mycompany.com/artifactory/artifacts-snapshot-local ,并且存根jar出现在此处.我已经完成了生产器的mvn安装,当我再次运行测试时,我收到此错误在本地存储库中找到了工件,但您已明确声明应从远程对象中下载该工件."

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".

当您在本地安装存根,然后尝试从工件上下载存根时会发生这种情况,但是SHA有所不同,因此Aether(下载存根的引擎)会选择本地存根.在这种情况下,我们抛出一个异常,因为您想从远程位置下载存根而不是从本地获取.

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.

尝试下载[remote0( https://artifactory.mycompany.com/artifactory/artifacts-snapshot-local ,默认为releases + snapshots)]] org.eclipse.aether.resolution.ArtifactResolutionException:找不到工件com.mycompany.domain:service-name:jar:stubs:1.6.0-SNAPSHOT

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

这看起来像在Artifactory中,您在某些Maven元数据中输入的内容是最新的jar为1.6.0-SNAPSHOT,但JAR不再存在.您可以仔细检查它是否确实存在吗?

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?

更新:

如果您的工件实例需要凭据或位于代理之后,则可以使用以下值:

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

您可以提供stubrunner.usernamestubrunner.passwordstubrunner.proxyHoststubrunner.proxyPort

这篇关于Spring Cloud Contract问题从Artifactory检索存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆