3

I have a Maven project that consists of several modules. I have a single POM file that I use to invoke the build of all dependent modules. What I want to do is to copy a bunch of files to a single location and zip them up once, after the package lifecycle of all the sub-modules has completed.

I've looked into antrun, but can't see how to make it run once. Currently it runs during the package phase of each module. Here's my parent POM file (simplified)

<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>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<name>project</name>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
    <module>../module1</module>
    <module>../module2</module>
</modules>
<dependencies>
    ...
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <mkdir dir="product" />
                            <copy todir="product">
                                <fileset dir="../module1/doc/release">
                                    <include name="*.pdf" />
                                </fileset>
                                <fileset dir="../module2/doc/release">
                                    <include name="*.pdf" />
                                </fileset>
                                <fileset dir="../module1/target">
                                    <include name="*.war" />
                                </fileset>
                                <fileset dir="../module2/target">
                                    <include name="*.war" />
                                </fileset>
                            </copy>
                            <copy file="app.properties" todir="cesium" />

                            <zip basedir="product" destfile="dist.zip"></zip>

                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

<properties>
    ...
</properties>

Hopefully it's clear what I'm trying to do. I just want the antrun task to happen after the package lifecycle, and only once, not for each module.

I understand that I might not be approaching this step the right way, but I'm unclear how best to aproach this with Maven. Any thoughts appreciated.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Mick Sear
  • 1,549
  • 15
  • 25
  • Hey, since mohommad shamsi gave you a good answer, make sure you mark his answer as the accepted answer. – deterb Sep 06 '10 at 20:14

1 Answers1

2

Try the Maven Assembly Plugin.

Here are the Maven Assembly Plugin Examples.

reevesy
  • 3,452
  • 1
  • 26
  • 23
mhshams
  • 16,384
  • 17
  • 55
  • 65
  • Excellent, thanks. First attempt *almost* did what I wanted, but I'm sure experimentation will get there. Thanks for an accurate and fast response! – Mick Sear Aug 26 '10 at 15:49
  • I ended up getting it working, using the assembly plugin with a format of zip, and a combination of fileSets and files. Works perfectly, thanks – Mick Sear Aug 26 '10 at 16:28