Maven multi-module project – copying all “package” JARS from submodules into parent/target/

You could try the maven-dependency-plugin:copy plugin:goal.

You will have to add this to the pom of all submodules that you want to copy.
EDIT: Or just in the parent pom (see comments).

    <build>
        <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-dependency-plugin</artifactId>
              <executions>
                <execution>             
                  <id>copy-artifact</id>
                  <phase>package</phase>
                  <goals>
                    <goal>copy</goal>
                  </goals>
                  <configuration>
                    <artifactItems>
                        <artifactItem>
                          <groupId>${project.groupId}</groupId>
                          <artifactId>${project.artifactId}</artifactId>
                          <version>${project.version}</version>
                          <type>${project.packaging}</type>
                        </artifactItem>
                    </artifactItems>
                    <outputDirectory>../Main/target/dependencies</outputDirectory>
                  </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
    </build>

If you do put this in the parent pom, keep in mind that it will work nicely only if your whole project is one module deep. Meaning that if the the modules under the parent module have their own submodules, they will not end up in the desired folder. Your folder structure will look like this:

- Parent
  - Module 1
    - Sub module 1
    **Main**
  - Module 2
  **Main**

To prevent this, create a dedicated module with above configuration, and specify manually each module that you want to copy. This way all modules, no matter how deep they are will end up in one folder.

Leave a Comment