在多模块项目的子模块中忽略了maven-release-plugin目标

时间:2018-02-23 19:54:08

标签: java maven maven-release-plugin

我有一个多模块Maven项目。该项目的布局如下

project/
  pom.xml

  types/
    pom.xml

  client/
    pom.xml

  service/
    pom.xml

typesclient模块构建为JAR,service构建为WAR。我使用maven-release-plugin创建了这个项目的新版本。我会喜欢让发布插件在执行service模块发布时调用额外的目标。

发布插件在根pom中配置如此(没什么特别的):

<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.5.3</version>
</plugin>

...并在service pom中配置了这样的插件以及我试图通过<goals>参数调用的插件:

<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <configuration>
    <goals>deploy dockerfile:build dockerfile:push</goals>
  </configuration>
</plugin>

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>dockerfile-maven-plugin</artifactId>
  <configuration>
    <repository>12345.ecr.us-east-1.amazonaws.com/project</repository>
  </configuration>
</plugin>

我的想法是,我想为service模块构建一个Docker镜像,但是为项目中的其他模块构建图像没有意义。但是,在剪切新版本时,永远不会调用service pom文件中的目标配置。

Maven版本:3.3.3

maven-release-plugin:2.5.3

JDK:Oracle 1.8.0u144

正在使用的命令:

mvn -Pstaging -B clean release:clean release:prepare release:perform

我无法分享此命令的输出。

我已经确认相关配置似乎是通过

应用的
mvn -Pstaging help:effective-pom 

我的问题是:我试图通过发布插件实现的目标是什么?我还没有找到任何表明它不可能的问题或文章。

1 个答案:

答案 0 :(得分:1)

警告我从未使用dockerfile-maven-plugin,请尝试发布配置文件而不是目标。

步骤1.在project/pom.xml中编辑发布插件配置。

<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.5.3</version>   <!-- should define in pluginManagement -->
  <configuration>
    <releaseProfiles>publish-docker</releaseProfiles>
    <!-- other plugin config -->
  </configuration>
</plugin>

为有意义的配置文件选择一个名称。我将使用publish-docker作为名称。

步骤2.将具有该名称的个人资料添加到service/pom.xml

<profiles>
  <profile>
    <id>publish-docker</id>
    <build>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>dockerfile-maven-plugin</artifactId>
        <configuration>
          <repository>12345.ecr.us-east-1.amazonaws.com/project</repository>
        </configuration>
        <executions>
          <execution>
            <id>docker-publish</id>
            <phase>deploy</phase>  <!-- important -->
            <goals>
              <goal>build</goal>
              <goal>push</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </build>
  </profile>
</profiles>

此配置文件包含将dockerfile:builddockerfile:push目标绑定到deploy阶段的插件配置。 release插件将为每个模块启用publish-docker配置文件。该配置文件仅存在于service模块中,以便它运行。

我注意到另一件事。在发布命令中:

mvn -Pstaging -B clean release:clean release:prepare release:perform

我怀疑在发布期间实际上没有应用-Pstaging部分。发布插件为每个目标运行分叉另一个进程。要将参数传递给fork,需要arguments参数:

mvn -Pstaging -Darguments="-Pstaging" -B clean release:clean release:prepare release:perform