4

オフラインで正常に動作する 2 つのコンシューマーと 1 つのプロデューサーのテストがありますが、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 インストールを実行しましたが、テストを再度実行すると、「アーティファクトはローカル リポジトリで見つかりましたが、リモート リポジトリからダウンロードする必要があると明示的に述べています」というエラーが表示されます。

また、プロデューサーのスタブへの依存関係をコンシューマーに追加しようとしましたが、同様のエラーが発生します。また、プロデューサーの特定のバージョンとの依存関係が追加されるため、回避したいと思います。

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

私が欠けているものについて何か考えはありますか?前もって感謝します

4

2 に答える 2