多模块Maven项目中的聚合依赖项 [英] Aggregate Dependencies in a Multi-Module Maven Project

查看:147
本文介绍了多模块Maven项目中的聚合依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何在一个多模块项目中聚合我的Maven依赖项.例如,如果我有:

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

然后运行mvn dependency:copy-dependencies,最终得到以下依赖项:

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

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

我真正想要的是,如果我在根pom文件夹中运行mvn命令,则所有依赖项都将被复制到root pom/dependency.是否有一个使我获得根pom输出目录的maven属性? (类似于${project.build.directory})?我意识到我可以在事发后将所有依赖项文件夹都复制到同一位置,但是我希望有一些清洁的方法.

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.

推荐答案

您将必须配置依赖项插件才能将依赖项复制到特定位置.这可以通过outputDirectory配置属性来完成.

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>

但是,如果您尝试执行此操作以进行分发,则建议您使用 Maven程序插件

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

文档说:

Maven 2.0的Assembly Plugin主要用于允许用户聚合 项目输出及其依赖项,模块,站点文档和其他文件 到一个可分发的存档中.

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.

这篇关于多模块Maven项目中的聚合依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆