在Maven中为多项目强加构建顺序

时间:2011-07-06 08:26:15

标签: maven maven-3

我有一个像maven这样的多项目:

paren-project
  -> plugin-project
  -> testbed-project

plugin项目生成一个JAR,手动将其复制到testbed的特定子目录(使用等嵌入式脚本)。重点:我不希望插件JAR位于testbed的类路径中。

但我找不到强制插件项目在测试平台项目之前构建的解决方案。如果我将插件项目设置为testbed项目的依赖项,则会将其添加到类路径中。

任何解决方案,还是我必须切换到等构建系统?

2 个答案:

答案 0 :(得分:18)

正如http://maven.apache.org/guides/mini/guide-multiple-modules.html

所述
  

反应堆排序

Because modules within a multi-module build can depend on each other, 
it is important that The reactor sorts all the projects in a way that 
guarantees any project is built before it is required.

The following relationships are honoured when sorting projects:
     
      
  1. 项目依赖于构建中的另一个模块
  2.   
  3. 插件声明插件是构建中的另一个模块
  4.   
  5. 插件依赖于构建中的另一个模块
  6.   
  7. 在构建
  8. 中的另一个模块上构建扩展声明   
  9. 模块元素中声明的顺序(如果没有其他规则适用)
  10.         

    请注意,仅使用“实例化”引用 - dependencyManagement   和pluginManagement元素不会导致更改反应堆排序顺序

答案 1 :(得分:7)

Maven是一个多功能的系统。无需切换。

您可以像这样添加依赖项:

<dependency>
  <groupId>group</groupId> 
  <artifactId>artifact</artifactId> 
  <optional>true</optional> 
</dependency>

这样,依赖关系不会包含在类路径中。

详细了解Optional Dependency