maven-assembly-plugin 在没有被告知的情况下循环遍历每个模块

maven-assembly-plugin loops over each module without being told to do so

我只是想将一些文件复制到一些目录中,并使用这个插件,因为我被告知它很方便。但是,每当我尝试执行 mvn install 时,插件都会以某种方式尝试遍历我的 pom.xml 中的每个模块(我从未要求它做这种事情)并尝试执行一些操作,然后给出错误:

Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (make-install-assembly) on project untoldProject Failed to create assembly: Error creating assembly archive install: You must set at least one file.

我希望此插件仅对我已经在我的程序集文件中的路径中指定的某些模块(和非模块的文件夹)运行。所以我不知道为什么插件会尝试为每个模块执行此操作。

这是我的 pom.xml 我使用插件的地方:

<!-- This plugin is used to copy the necessary files to project.release/install folder -->
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.6</version>
          <executions>
            <execution>
              <id>make-install-assembly</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
              <inherited>true</inherited>
              <configuration>
                <descriptors>
                  <descriptor>assembly.xml</descriptor>
                </descriptors>
                <appendAssemblyId>false</appendAssemblyId>
                <attach>true</attach>
              </configuration>
            </execution>
          </executions>
        </plugin>

这是我的asssembly.xml,我在其中指定了我要复制的内容:

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>install</id>
    <formats>
        <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>project.release/template</directory>
            <outputDirectory>project.release/install</outputDirectory>
            <lineEnding>unix</lineEnding>
            <filtered>true</filtered>
            <includes>
                <include>run.all.sh</include>
                <include>kill.all.sh</include>
                <include>packlogs.sh</include>
            </includes>
            <excludes>
                <exclude>config.properties</exclude>
                <exclude>run.all.ant</exclude>
                <exclude>run.ant</exclude>
                <exclude>packlogs.sh</exclude>
                <exclude>install.sh</exclude>
            </excludes>
        </fileSet>
    </fileSets>
</assembly>  

鉴于此,为什么插件会尝试对每个模块执行此操作?我只希望它发生在一个名为 project.release 的模块上,仅此而已。我将 pom.xmlassembly.xml 都放到了父目录中,供您参考。

更新: 对于那些想看看我的项目层次结构的人,这是我的主人 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>runtime_project</groupId>
   <artifactId>runtime_project.master</artifactId>
   <version>1.0.0-SNAPSHOT</version>
   <packaging>pom</packaging>
   <properties>
      <jdk.version>1.8</jdk.version>
   </properties>
   <modules>
      <module>project.messages</module>
      <module>project.base</module>
      <module>project.logging</module>
      <module>project.mission.launch</module>
      <module>project.mission.detach</module>
      <module>project.settingsStore</module>
   </modules>
   <build>
      <sourceDirectory>src/</sourceDirectory>
      <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
               <source>${jdk.version}</source>
               <target>${jdk.version}</target>
            </configuration>
        </plugin>  

        <!-- This plugin is used to delete the contents of the project.release/install folder-->
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>auto-clean</id>
                    <phase>initialize</phase>
                    <goals>
                      <goal>clean</goal>
                    </goals>
                </execution>
           </executions>
            <configuration>
                <verbose>true</verbose>
                <excludeDefaultDirectories>true</excludeDefaultDirectories>
                <filesets>
                  <fileset>
                    <directory>project.release/install</directory>
                    <followSymlinks>false</followSymlinks>
                    <useDefaultExcludes>true</useDefaultExcludes>
                    <includes>
                      <include>**/*</include>
                    </includes>
                  </fileset>
                </filesets>
            </configuration>
        </plugin>   
        <!-- This plugin is used to copy the necessary files to project.release/install folder -->
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.6</version>
          <executions>
            <execution>
              <id>make-install-assembly</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
              <inherited>true</inherited>
              <configuration>
                <descriptors>
                  <descriptor>deploy.xml</descriptor>
                </descriptors>
                <appendAssemblyId>false</appendAssemblyId>
                <attach>true</attach>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
   </build>
</project>

Given this, why does the plugin try to do this operation for every module?

因为这是多模块项目的本质。

I just want it to happen for one module, called project.release, and that's it. I put both of my pom.xml and assembly.xml to the parent directory, for your information.

我给出一些提示,不是完整的解决方案。

  1. 创建一个名为 project.release 的附加模块。将它添加到根 POM 中的 <modules> 元素。顺序无关紧要
  2. 将 maven-assembly-plugin 的插件条目从根 POM 移动到 project.release
  3. 的 POM
  4. project.release的POM中,根据需要添加对其他模块的依赖。
  5. project.release的文件夹中,将程序集描述符放在src/main/assembly中。描述符中的目录条目应该相对于 project.release
  6. 的模块根目录