2011-05-04 105 views
3

我有以下问题。我有一个多模块项目。我想在顶层pom上运行maven-assembly插件,这也是其模块的父pom。我希望插件只能在顶级pom上执行。目前它也尝试在所有子模块上执行。我不想这样,我只需要抓住从所有模块的所有源代码和子模块在一个地方Maven Assembly Plugin在子项目上执行

这里是我的描述符(顶层目标目录):

<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只包含一些依赖,我想在所有模块进行inheritaed。子模块将当前的pom作为父项。 现在,如果我运行:

MVN装配:单-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 =假

,但它不help.Adding

-Dassembly.ignoreMissingDescriptor = true

也没有帮助。有任何想法吗?

回答

2

-Dassembly.runOnlyAtExecutionRoot =真

这是使作为描述它的工作特性。

2

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

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

+1

你会写你所谈论的标签,和你在哪里指定。无论如何,应该有另一种解决方案,因为当你有300个项目需要一些时间,除此之外,我不想阻止其他事情的继承。 – alexmaig 2011-09-08 08:50:29

+2

其实,IMO false需要在** parent ** pom.xml中 - 这样子模块才不会继承那个执行。不确定是否适用于您的情况。看到我的答案。 – 2011-11-01 03:49:09

+0

将无法​​工作:(这正是什么-Dexecution.inherited = false。 – alexmaig 2011-12-07 09:24:36

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

5

将此置入maven-assembly-plugin的配置中,在父pom中。

<runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot> 
0

你可以行家阶段没有内禁用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> 
相关问题