春季云合同未在Maven多模块项目中部署到文物中



我有一个多模块项目,每个模块在该项目中都可以很好地部署到文物中,直到我将Spring-Cloud-Cartract-Cartract-Maven-Plugin添加到其中一个模块中(服务,因为它是一个服务,因为它是一个模块生产者API)。

该项目具有以下结构:

parent
- common (shared DTOs)
- client
- service

我们希望将来删除客户端和常见,并在消费者中有假装客户端减少耦合,并拥有一个没有内部模块的基本项目,但是现在我们必须保持这种结构。

我首先注意到这些存根没有被推到文物上,所以我最初的解决方法是将其添加到Jenkins Pipeline

sh './mvnw clean deploy -U --projects=xxx-service'

它部署了服务和存根,但是我注意到执行此命令时没有部署任何模块:

sh './mvnw clean deploy -U'

这是输出的末尾:

[INFO] Installing /xxx/xxx-service/target/xxx-service-1.7.0-SNAPSHOT.jar to /xxx/.m2/repository/xxx/xxx-service/1.7.0-SNAPSHOT/xxx-service-1.7.0-SNAPSHOT.jar
[INFO] Installing /xxx/xxx-service/pom.xml to /xxx/.m2/repository/xxx/xxx-service/1.7.0-SNAPSHOT/xxx-service-1.7.0-SNAPSHOT.pom
[INFO] Installing /xxx/xxx-service/target/xxx-service-1.7.0-SNAPSHOT-stubs.jar to /xxx/.m2/repository/xxx/xxx-service/1.7.0-SNAPSHOT/xxx-service-1.7.0-SNAPSHOT-stubs.jar
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ xxx-service ---
[INFO] Deploying xxx:xxx-service:1.7.0-SNAPSHOT at end

我试图将所有Maven配置移动到父型POM文件,并将合同和基本测试类保留在服务模块中。我已经看过此页面,该页面说明了如何配置插件,我已经看到我可以使用ContractSdirectory指定合同文件的目录,GmavenPlus-Plugin以指定生成的测试的目录和PackageWithBaseclasses的目录来指定基础课。但是,我看不到任何方法来指定基本类的目录。我无法将基本测试类移至父母,因为他们使用一些服务模块生成模拟的类别。

有什么方法可以做到这一点,还是我必须为合同创建一个单独的项目?

预先感谢

问题的原因:

我在我的API扩展的父项目中有一个:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>${maven-deploy-plugin.version}</version>
        <configuration>
            <deployAtEnd>true</deployAtEnd>
        </configuration>
    </plugin>

为什么这是一个问题:

Maven-Deploy-Plugin似乎与使用Spring-Cloud-Contract-Contract-Maven-Plugin之类的扩展名的插件与多模块项目冲突。这里有一个已知的问题,请探讨杰罗姆的答案,也在这里。

解决方案1:

从上一个块中删除Deployatend选项,因此是:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>${maven-deploy-plugin.version}</version>
    </plugin>

解决方案2:

尽管不需要所有模块,都将插件配置在所有模块中。为此:

  • 在所有模块上添加一个空的"合同"文件夹

  • 将其添加到服务模块的POM文件:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-maven-plugin</artifactId>
            <version>${spring-cloud-contract.version}</version>
            <extensions>true</extensions>
            <configuration
                <baseClassForTests>com.xxx.BaseContractTest</baseClassForTests>
            </configuration>
        </plugin>
    </plugins>
</build>
  • 将其添加到其他模块的POM文件中:
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-maven-plugin</artifactId>
            <version>${spring-cloud-contract.version}</version>
            <extensions>true</extensions>
        </plugin>
    </plugins>
</build>

最新更新