Maven Assembly Plugin在子项目上执行

时间:2011-05-04 14:29:00

标签: maven-assembly-plugin

我有以下问题。我有一个多模块项目。我想在顶层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 assembly: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

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

5 个答案:

答案 0 :(得分:7)

将其放入父pom中的maven-assembly-plugin的配置中。

<runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>

答案 1 :(得分:2)

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

我在子模块的pom.xml中通过xml标签<inherited>false</inherited>定义了非继承,它似乎有效。

答案 2 :(得分:2)

-Dassembly.runOnlyAtExecutionRoot =真

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

答案 3 :(得分:0)

不确定我是否了解情况。但要禁用插件的执行,请尝试以下操作:

        <!-- 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并将其放入此代码段....

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

HTH

答案 4 :(得分:0)

您可以在maven阶段中禁用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>