Benny
Benny

Reputation: 1568

With Maven2, how would I specify a custom directory to which a dependency should be copied?

Basically, I have a multi-module project consisting of 5 different modules. One of the modules is kind of the parent module to the other 4, meaning the other 4 need to be built before the 5th, so you could say that each of the 4 modules is a dependency of the 5th. Thus, I've made dependency entries for each of the modules in the 5th module's pom.xml.

However, when I build the project, I don't want those 4 dependencies copied to the "lib" directory of the 5th module. I'd like to specify the directory into which each of them should be placed explicitly.

Is there any way to do this with Maven2?

Thanks for your help,

B.J.

Upvotes: 1

Views: 212

Answers (1)

Pascal Thivent
Pascal Thivent

Reputation: 570295

I'm not sure I understood everything (from where does this lib directory come from, when do you want the copy to happen exactly?) but the Maven Dependency Plugin might help, its dependency:copy goal takes an outputDirectory per dependency. Below the sample taken from the Usage page:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>[ groupId ]</groupId>
                  <artifactId>[ artifactId ]</artifactId>
                  <version>[ version ]</version>
                  <type>[ packaging ]</type>
                  <classifier> [classifier - optional] </classifier>
                  <overWrite>[ true or false ]</overWrite>
                  <outputDirectory>[ output directory ]</outputDirectory>
                  <destFileName>[ filename ]</destFileName>
                </artifactItem>
              </artifactItems>
              <!-- other configurations here -->
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Change the lifecycle phase binding according to your needs.

But as I said, this answer is more an hint, maybe using a custom assembly would be more appropriate. If it doesn't help, please provide more details.

Upvotes: 1

Related Questions