4

I have a multi module project. Each module is packaged in a jar/war file in his own /target folder.

I want to take every module jar/war files and some config files, and put everything in a zip.

How to do that? I try with assembly plugin, but all i've managed to do so far is a zip of each module in their respective /target folder, so pretty useless ^^

Lempkin
  • 1,458
  • 2
  • 26
  • 49

1 Answers1

7

First is to create a separate module let us call it dist add to the parent as new module and add all modules which you like to see in the resulting zip file as dependencies including the type war, jaretc.

The <packaging>pom</packaging> should be given cause this module does not contain any java code which needed to be compiled etc. We only want to create zip file which contains the given dependencies.

 <project ..>

 <packaging>pom</packaging>

 <dependencies>
    <dependency>
      <groupId>module-1</groupId>
      <artifactId>module-1-artifact</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>module-2</groupId>
      <artifactId>module-2-artifact</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>make-bundles</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>proj1-assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Add the following descriptor:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">

  <id>dist-assembly</id>

  <formats>
      <format>zip</format>
  </formats>

  <includeBaseDirectory>false</includeBaseDirectory>

  <dependencySets>
      <dependencySet>
          <outputDirectory>/</outputDirectory>
          <useProjectArtifact>false</useProjectArtifact>
          <unpack>false</unpack>
      </dependencySet>
  </dependencySets>
</assembly>

The dependencies are needed to be sure the order of execution is correctly calculated by Maven.

If you need supplemental configuration in that zip file you can add those files into src/main/config for example and add fileSets parts in the assembly descriptor.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235