tags:

views:

153

answers:

2

I am trying to figure out how to aggregate my maven dependencies in a multi-module project. For example, if I have:

root pom/project1
root pom/project2

and I run mvn dependency:copy-dependencies, I end up with the dependencies in:

root pom/project1/target/dependency
root pom/project2/target/dependency

What I really want is that if I run the mvn command in the root pom folder, all of the dependencies to be copied to root pom/dependency. Is there a maven property that gets me the output directory of the root pom? (similar to ${project.build.directory})? I realize that I can just copy all the dependency folders to the same place after the fact, but I was hoping for something a little cleaner.

A: 

You will have to configure the dependency plugin to copy depdendencies to a particular location. This can be done by the outputDirectory configuration property.

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-dependency-plugin</artifactId>
   <executions>
      <execution>
         <id>copy-dependencies</id>
         <phase>package</phase>
         <goals>
            <goal>copy-dependencies</goal>
         </goals>
         <configuration>
              <outputDirectory>${outputDir}</outputDirectory>
         </configuration>
      </execution>
   </executions>
</plugin>

But if you trying to do this for distribution, I'd recommend you create an assembly using the maven assembly plugin

The documentation says:

The Assembly Plugin for Maven 2.0 is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.

naikus
Thank you! That looks like what I need.
Greg
A: 

What I really want is that if I run the mvn command in the root pom folder, all of the dependencies to be copied to root pom/dependency. Is there a maven property that gets me the output directory of the root pom? (similar to ${project.build.directory})?

No, because modules shouldn't actually be aware of that.

I realize that I can just copy all the dependency folders to the same place after the fact, but I was hoping for something a little cleaner.

The Maven way would to use the Maven Assembly Plugin and a custom descriptor. But if you're not familiar with the Maven Assembly Plugin and its descriptor format, it won't be easy.

A less clean but easier approach would be to configure the Maven Dependency plugin to copy the dependencies into the parent project using a relative path. Something like this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.1</version>
  <configuration>
    <outputDirectory>../root_pom/target/dependency</outputDirectory>
  </configuration>
</plugin>

But as I said, this introduces tight coupling between modules and the root project which is not good at all (and I wouldn't go further by including the goal invocation as part of the build, modules should remain independent and you should be able to build one module without "checkouting" the parent).

Pascal Thivent
I'm going to try the assembly plugin, thanks!
Greg