Impose build order for a multi-project in Maven

筅森魡賤 提交于 2019-12-30 02:56:30

问题


I have a multi project in maven like this:

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

The plugin project generates a JAR, which is manually copied to a specific subdirectory of testbed (using whatever embedded script like groovy or ant). The important point: I don't want the plugin JAR to be in the classpath of testbed.

But I cannot found the solution to force the plugin project to be build BEFORE the testbed project. If I set the plugin project as dependency of the testbed project, it is added in the classpath.

Any solution, or do I have to switch to a build system like gradle, ivy or ant ?


回答1:


As it is mentioned at the http://maven.apache.org/guides/mini/guide-multiple-modules.html

Reactor Sorting

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. project dependency on another module in the build
  2. plugin declaration where the plugin is another modules in the build
  3. plugin dependency on another module in the build
  4. build extension declaration on another module in the build
  5. the order declared in the modules element (if no other rule applies)

Note that only "instantiated" references are used - dependencyManagement and pluginManagement elements will not cause a change to the reactor sort order




回答2:


Maven is a versatile system. No need to switch.

You can add the dependency like this:

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

This way, the dependency will not be included in the classpath.

Read more about Optional Dependency



来源:https://stackoverflow.com/questions/6593503/impose-build-order-for-a-multi-project-in-maven

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!