Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
    <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?

like image 639
alexmaig Avatar asked Dec 13 '22 13:12

alexmaig


2 Answers

Put this into the configuration of the maven-assembly-plugin, in the parent pom.

<runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
like image 53
panagdu Avatar answered Jan 13 '23 02:01

panagdu


-Dassembly.runOnlyAtExecutionRoot=true

This is the property that makes it work as described.

like image 36
alexmaig Avatar answered Jan 13 '23 02:01

alexmaig