Question

I have a multimodule Maven project with assembly configurations for some of the submodules that only depend on dependencies defined in the parent pom (submodules 1 and 2 below). Now I added a new submodule 3 that has submodule-specific dependencies and had to move its assembly configuration to within the module. So far so good.

The problem is that doing mvn assembly:assembly at the root level won't invoke the assembly for the new submodule 3 but only for the assembly configurations defined at the parent pom level. How can I fix this?

Sample structure of my project:

  - pom.xml # parent pom
  - src
    |---main
        |---assembly
            |---assembly-submodule1.xml
            |---assembly-submodule2.xml
  - submodule1      
  - submodule2
  - submodule3
    |---pom.xml
    |---src
        |---main
            |---resources
                |---assembly
                    |---assembly-submodule3.xml

Parent pom.xml assembly configuration that does not link to the assembly file of the submodule 3:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
            <descriptors>
                    <descriptor>src/main/assembly/assembly-submodule1.xml</descriptor>
                    <descriptor>src/main/assembly/assembly-submodule2.xml</descriptor>
            </descriptors>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
            <archive>
                    <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
            </archive>
    </configuration>
</plugin>
Was it helpful?

Solution

In your parent POM add

<modules>
    <module>submodule3</module>
</modules>

It will then build the submodule 3 pom, so you may need to configure the maven assembly plugin in the submodule3 pom too

If these are already there, try binding the assembly to the package phase like so:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptors>
            <descriptor>assembly.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>package</id>
            <goals>
                <goal>assembly</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>

Do this for both parent and sub module. Then run mvn clean package instead of mvn assembly:assembly at the top level.

If you needto be able to run a build but NOT run the assembly, you can create a profile for the assembly and add this to that profile. E.g.

<profiles>
    <profile>
        <id>assembly</id>
        <build>
            <plugins>
                <!-- Put assembly Plugin here -->
            </plugins>
        </build>
    </profile>
</profiles>

Now ehen you run mvn clean package, it won't run the assembly.

But if you run with the assembly profile like this:

mvn clean package -P assembly

it will.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top