首页 > 解决方案 > maven-assembly-plugin 步骤失败:“[警告] 在此工件包含过滤器中从未触发以下模式”

问题描述

我正在尝试将全局版本属性添加到我的多模块 Maven 项目中,以便我可以通过更新单个属性而不是多个 pom 文件来轻松更新所有模块的版本。问题是这个属性破坏了 maven-assembly-plugin,它将编译模块 jar 收集到一个 zip 文件夹中以进行分发。当版本在所有 pom 文件中被硬编码时,一切都运行得很好。但是,当我转换为属性时,各个模块 jar 仍然编译,但 maven-assembly-plugin 步骤在以下警告后失败:“[警告] 在此工件包含过滤器中从未触发以下模式”

程序集过滤器似乎缺少模块,我无法解释为什么在使用全局属性时会发生这种情况,或者如何修复它。

项目结构:

    MyProject
        --ModuleA
          pom.xml
        --ModuleB
          pom.xml
        --Distribution
          src\main\assembly\distribution-assembly.xml
          pom.xml
    pom.xml

我的项目/pom.xml:

    <groupId>com.mycompany</groupId>
    <artifactId>MyProject</artifactId>
    <packaging>pom</packaging>
    <version>${global.version}</version>

    <properties>
        <global.version>1.0.1-SNAPSHOT</global.version>
    </properties>

模块A/pom.xml:

    <parent>
        <artifactId>MyProject</artifactId>
        <groupId>com.mycompany</groupId>
        <version>${global.version}</version>
    </parent>
    <artifactId>ModuleA</artifactId>

模块B/pom.xml:

    <parent>
        <artifactId>MyProject</artifactId>
        <groupId>com.mycompany</groupId>
        <version>${global.version}</version>
    </parent>
    <artifactId>ModuleB</artifactId>

分发/pom.xml:

    <parent>
        <artifactId>MyProject</artifactId>
        <groupId>com.mycompany</groupId>
        <version>${global.version}</version>
    </parent>
    <packaging>pom</packaging>
    <artifactId>Distribution</artifactId>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <descriptors>
            <descriptor>
              src/main/assembly/distribution-assembly.xml
            </descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>
                single
              </goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

分发/src/main/assembly/distribution-assembly.xml:

    <id>bin</id>
    <formats>
      <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <moduleSets>
      <moduleSet>
        <useAllReactorProjects>true</useAllReactorProjects>
        <includes>
          <include>com.mycompany:ModuleA</include>
          <include>com.mycompany:ModuleB</include>
        </includes>
        <binaries>
          <outputDirectory>MyBuildFolder</outputDirectory>
          <outputFileNameMapping>mycompany${module.artifactId}.${module.extension}</outputFileNameMapping>
          <unpack>false</unpack>
         </binaries>
       </moduleSet>
     <moduleSets>

警告:

    [WARNING] The following patterns were never triggered in this artifact 
    inclusion filter:
    o  'com.mycompany:ModuleA'
    o  'com.mycompany:ModuleB'

错误:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly- 
    plugin:2.4:single (make-assembly) on project Distribution: 
    Failed to create assembly: Error creating assembly archive bin: You must 
    set at least one file. -> [Help 1]

标签: javamavenmaven-assembly-plugin

解决方案


尝试将您的 ModuleA 和 ModuleB 添加为分发 pom 的依赖项。

Dstiution/pom.xml 应该如下所示:

<parent>
    <artifactId>MyProject</artifactId>
    <groupId>com.mycompany</groupId>
    <version>${global.version}</version>
</parent>
<packaging>pom</packaging>
<artifactId>Distribution</artifactId>

<dependencies>
    <dependency>
        <groupId>com.mycompany</groupId>
        <artifactId>ModuleA</artifactId>
        <version>${global.version}</version>
    </dependency>
    <dependency>
        <groupId>com.mycompany</groupId>
        <artifactId>ModuleB</artifactId>
        <version>${global.version}</version>
    </dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <descriptors>
          <descriptor>
            src/main/assembly/distribution-assembly.xml
          </descriptor>
        </descriptors>
      </configuration>
      <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
          <goals>
          <goal>
            single
          </goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>


推荐阅读