BillMan
BillMan

Reputation: 9924

Best way to copy multi module project in maven

I have a maven project in which I would like to unpack all the child modules of a mutli module project. Does anyone know if the best way to approach this? There are over 100 modules in this project and I'm trying to avoid having to copy all this information somewhere else.

Upvotes: 1

Views: 794

Answers (1)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298818

First you will need to create a pom.xml file that has all the projects as dependencies.

  1. If there is one submodule that has all other submodules as dependencies, then you are in luck, just add a dependency to that submodule.
  2. If not, you will have to write a script or program that gathers the groupIds, artifactIds, versions (and packagings) of all the submodules. And creates a pom.xml with all of them as dependencies.

Then, in this project, you can use dependency:unpack-dependencies to unpack the projects:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
     <execution>
        <id>unpack-projects</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>unpack-dependencies</goal>
        </goals>
        <configuration>
          <includeGroupIds>com.basegroupId*</includeGroupIds>
        </configuration>
     </execution>
  </executions>
</plugin>

(Set includeGroupIds to a pattern that matches all submodule groupIds)

Now you just have to call

mvn generate-sources

(or any other phase you configure in the execution)

Upvotes: 1

Related Questions