gpt4 book ai didi

spring-cloud - Spring Cloud Contract 出现从 Artifactory 检索 stub 的问题

转载 作者:行者123 更新时间:2023-12-04 05:05:30 26 4
gpt4 key购买 nike

我对两个消费者和一个离线工作正常的生产者进行了测试,但是当我更改它们以从 Artifactory 检索 stub 时,消费者测试失败。

这是离线工作的代码:

@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 stub jar 出现在那里。我已经完成了生产者的 mvn 安装,当我再次运行测试时,我收到此错误“在本地存储库中找到了工件,但您已明确声明它应该从远程存储库下载”。

我还尝试向消费者添加对生产者 stub 的依赖,但我遇到了类似的错误。我宁愿避免它,因为它会添加与特定版本的生产者的依赖关系:

<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 文件中:

<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 的内容:

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

知道我缺少什么吗?提前致谢

最佳答案

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



当您在本地安装 stub ,然后尝试从 artifactory 下载它但 SHA 不同时,就会发生这种情况,因此 Aether(下载 stub 的引擎)选择本地的。在这种情况下,我们抛出一个异常,因为您想从远程位置下载 stub ,而不是从本地下载 stub 。

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 不再存在。你能仔细检查一下它真的在那里吗?

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:



这只能证明您的工件/项目设置有些困惑。如果您对版本进行硬编码,事情仍然不起作用吗?

更新:

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

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

您可以提供 stubrunner.username , stubrunner.password , stubrunner.proxyHoststubrunner.proxyPort

关于spring-cloud - Spring Cloud Contract 出现从 Artifactory 检索 stub 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47513965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com