views:

41

answers:

4

We have a aggregation .pom set up to include several, individual modules, similar to the Maven documentation:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
  <packaging>pom</packaging>

  <modules>
    <module>my-module</module>
    <module>my-module-2</module>
  </modules>
</project>

Is there a way to get the artifacts from the builds (.JAR files) from these two modules into a common 'dist' directory after building? I did not want to adjust to output directory for the individual modules from "my-module/target" since they can be built separately as well.

I'm a Maven new-comer, so I'm sure there's an easy way to do this I'm missing.

A: 

i guess maven assembly plugin can do this

Pangea
A: 

As @Pangea said assembly plugin will do it. Just run assembly:assembly goal with appropriately set outputDirectory parameter.

more info at http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html

eugener
"Just" running `assembly:assembly` won't be enough.
Pascal Thivent
+1  A: 

Is there a way to get the artifacts from the builds (.JAR files) from these two modules into a common 'dist' directory after building?

The Maven Assembly Plugin can do that, it is very powerful and flexible. But power and flexibility also mean that this is not the most trivial plugin to use. In your case, the idea would be to generate a dir distribution from a moduleSets and you'll have to create a custom assembly descriptor for that.

I suggest starting with chapter 8.2. Assembly Basics of the Maven book and to pay a special attention to the chapter 8.5.5. moduleSets Sections.

Pascal Thivent
A: 

After reading more at the links from the other answers, here is what I'm going to try for now:

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>

            <executions>
                <execution>
                    <id>copy-jars</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>../src/my-module/target</directory>
                                <includes>
                                    <include>**/my-module*.jar</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Not exactly pretty, but while researching the Assembly plug-in for a possible longer term solution, this will do.

MattGWagner