Maven Assembly Plugin is executed on child projects
I have the following problem. I have a multimodule project. I want to run maven-assembly plugin on the toplevel pom that is also a parent pom for its modules. I want the plugin to be executed only on the top level pom. Currently it tries to execute also on all the submodules. I do not want this as I just need to grab all the sources from all the modules and submodules in one place (toplevel target directory.)
Here is my descriptor:
<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>
The pom file looks like this:
<?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>
开发者_C百科 <dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.8.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Parent pom just contains some dependencies that I want to be inheritaed in all modules. Submodules have the current pom as parent. Now if I run :
mvn assembly:single -Ddescriptor=somedes.xml
it runs ok on the toplevel pom and collect all the sources that I need. But it does not stop and start to execute this goal on all the subprojects, and of course there is no descriptor defined for the. How can I force the execution only on the toplevel 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.
I have tried to add:
-Dexecution.inherited=false
but it doesn't help.Adding
-Dassembly.ignoreMissingDescriptor=true
also didn't help. Any ideas?
Put this into the configuration of the maven-assembly-plugin, in the parent pom.
<runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
-Dassembly.runOnlyAtExecutionRoot=true
This is the property that makes it work as described.
You are right, you tried to use the param "-Dexecution.inherited=false"
.
I defined the non-inheritance by xml tag <inherited>false</inherited>
in the pom.xml of the children module, it seems to work.
Not sure if I understand the situation. But to disable execution of a plugin, try this:
<!-- 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>
You need to know the execution id from parent and put it to this snippet into ....
Here's a nice clear explanation: http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/
HTH
You could disable the maven-assembly-plugin
within maven phase none.
<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>
精彩评论