【问题标题】:Maven Assembly Plugin is executed on child projectsMaven Assembly Plugin 在子项目上执行
【发布时间】:2011-05-04 14:28:59
【问题描述】:

我有以下问题。我有一个多模块项目。我想在顶层 pom 上运行 maven-assembly 插件,它也是其模块的父 pom。我希望插件仅在顶级 pom 上执行。目前它也尝试在所有子模块上执行。我不希望这样,因为我只需要在一个地方(顶级目标目录)从所有模块和子模块中获取所有源。

这是我的描述符:

<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>src</id>
<formats>
    <format>zip</format>
</formats>
<moduleSets>
    <moduleSet>
        <includeSubModules>true</includeSubModules>
        <sources>
            <useDefaultExcludes>true</useDefaultExcludes>
            <includeModuleDirectory>false</includeModuleDirectory>
            <fileSets>
                <fileSet>
                    <outputDirectory>/</outputDirectory>
                    <useDefaultExcludes>true</useDefaultExcludes>
                    <includes>
                        <include>src/main/**</include>
                        <include>src/test/**</include>
                        <include>target/classes/**</include>
                    </includes>
                </fileSet>
            </fileSets>
        </sources>
    </moduleSet>
</moduleSets>

pom 文件如下所示:

<?xml version="1.0"?>
<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/maven-v4_0_0.xsd"
      >

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>myid</groupId>
    <artifactId>myartid</artifactId>
    <version>1.1</version>
</parent>
<groupId>myid2</groupId>
<artifactId>TopLevelBuild</artifactId>
<packaging>pom</packaging>
<version>5.5-SNAPSHOT</version>
<name>Some Application</name>
<modules>
    <module>1</module>
    <module>2</module>
    <module>3</module>
    <module>4</module>
    <module>5</module>
    <module>6</module>
</modules>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit-dep</artifactId>
        <version>4.8.2</version>
        <scope>compile</scope>
    </dependency>
</dependencies>
</project>

父 pom 只包含一些我希望在所有模块中继承的依赖项。子模块将当前 pom 作为父模块。 现在,如果我运行:

mvn 组装:single -Ddescriptor=somedes.xml

它在顶层 pom 上运行良好,并收集了我需要的所有资源。但它并没有停止并开始在所有子项目上执行这个目标,当然也没有为它定义描述符。如何仅在顶级 pom 上强制执行?

...
[INFO] Processing sources for module project: LAST MODULE
[INFO] Building zip: ..../target/TopLevelBuild-5.5-SNAPSHOT-src.zip
[INFO] ------------------------------------------------------------------------
[INFO] Building deploy
[INFO]    task-segment: [assembly:single]
[INFO] ------------------------------------------------------------------------
[INFO] [assembly:single {execution: default-cli}]
[INFO] Processing sources for module project: module1-submodule1:jar:5.5-SNAPSHOT
[INFO] Processing sources for module project: module1-submodule1:jar:5.5-SNAPSHOT
[INFO] Building zip: .../module1/target/module1-5.5-SNAPSHOT-src.zip
[INFO] ------------------------------------------------------------------------
[INFO] Building module1
[INFO]    task-segment: [assembly:single]
[INFO] ------------------------------------------------------------------------
[INFO] [assembly:single {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to create assembly: Error creating assembly archive src: You must set at least one file.

我已尝试添加:

-Dexecution.inherited=false

但这没有帮助。添加

-Dassembly.ignoreMissingDescriptor=true

也没有帮助。有什么想法吗?

【问题讨论】:

    标签: maven-assembly-plugin


    【解决方案1】:

    把这个放到maven-assembly-plugin的配置中,在父pom中。

    <runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
    

    【讨论】:

      【解决方案2】:

      -Dassembly.runOnlyAtExecutionRoot=true

      这是使它按描述工作的属性。

      【讨论】:

        【解决方案3】:

        你是对的,你尝试使用param "-Dexecution.inherited=false"

        我在children模块的pom.xml中通过xml标签&lt;inherited&gt;false&lt;/inherited&gt;定义了非继承,好像可以了。

        【讨论】:

        • 能不能写下你说的标签,在哪里指定。无论如何,应该有另一种解决方案,因为当您有 300 个项目时,这需要一些时间,此外我不想阻止其他事情的继承。
        • 实际上,IMO false 需要在 parent pom.xml 中 - 这样,子模块不会继承该执行。不确定是否适用于您的情况。看我的回答。
        • 不会工作 :( 这正是 -Dexecution.inherited=false 所做的。
        【解决方案4】:

        不确定我是否了解情况。但是要禁用插件的执行,试试这个:

                <!-- Don't run the reporting tool in submodule. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions combine.self="override" combine.>
                        <execution><id>reporting</id><phase>none</phase></execution>
                    </executions>
                </plugin>
        

        你需要知道父级的执行id,并把它放到这个sn-p到....

        这里有一个很好的清晰解释:http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/

        HTH

        【讨论】:

          【解决方案5】:

          您可以在 maven 阶段 none 中禁用 maven-assembly-plugin

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5</version>
            <executions>
              <execution>
                <phase>none</phase>
                <goals>
                  <goal>single</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          

          【讨论】:

            猜你喜欢
            • 2017-08-29
            • 1970-01-01
            • 2014-09-05
            • 1970-01-01
            • 1970-01-01
            • 2021-02-15
            • 2012-03-25
            • 2018-10-22
            • 2017-09-23
            相关资源
            最近更新 更多