Maven: Maven Assembly Plugin configuration with multiple modules in a maven project

夏侯俊美
2023-12-01

In the parent pom.xml, add the configuration

parent pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.test</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>

    <packaging>pom</packaging>

    <name>Parent</name>

    <modules>
        <module>child1</module>
        <module>child2</module>
        <module>child3</module>
    </modules>

    <build>
        <finalName>final-package-name</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

This POM simply directs the Assembly Plugin to use the assembly.xml assembly descriptor when executing.
Know more about Maven Assembly Plugin: http://maven.apache.org/plugins/maven-assembly-plugin/


The assembly.xml configuration content

assembly.xml

<assembly>
    <id>workflow</id>
    <formats>
        <format>zip</format> <!--The type of package which you want-->
    </formats>

    <fileSets>
        <fileSet>
            <directory>config</directory>
        </fileSet>
    </fileSets>

    <!-- <includeBaseDirectory>false</includeBaseDirectory> -->
    <moduleSets>
        <moduleSet>
            <includes>
                <include>org.test:child1</include>
            </includes>
            <sources>
                <includeModuleDirectory>false</includeModuleDirectory>
                <fileSets>
                    <fileSet>
                        <directory>target</directory>
                        <outputDirectory>../lib</outputDirectory>
                        <includes>
                            <include>*.jar</include>
                        </includes>
                    </fileSet>
                </fileSets>
            </sources>
        </moduleSet>

        <moduleSet>
            <includes>
                <include>org.test:child2</include>
            </includes>
            <sources>
                <fileSets>
                    <fileSet>
                        <outputDirectory>main</outputDirectory>
                        <directory>main</directory>
                    </fileSet>
                    <fileSet>
                        <directory>target</directory>
                        <outputDirectory>../lib</outputDirectory>
                        <includes>
                            <include>*.jar</include>
                        </includes>
                    </fileSet>
                </fileSets>
            </sources>
        </moduleSet>
    </moduleSets>
</assembly>

Konw more about the Assembly Descriptor Format: http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html


In order to generate your package, just run

1) mvn clean
2) assembly:assembly
 类似资料:

相关阅读

相关文章

相关问答