Maven的多模块项目的生命周期 [英] Maven multi module project lifecycle

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

问题描述

我有一个大型的多模块Maven项目和使用的编译器,神火和故障安全插件是。所有与神火运行我的单元测试,我与故障安全集成测试。为什么运行 MVN验证对整个项目,这似乎做到以下几点:

I have a large multi module maven project and am using the compiler, surefire and failsafe plugins. All of my unit tests run with surefire, and my integration tests with failsafe. Why running mvn verify on the whole project, it appears to do the following:


  1. 获取下一个模块运行(基于依赖图)

  2. 执行的整个生命周期该模块(初始化,编译,测试,集成测试,...)

  3. 重复,直到没有更多的模块

这是一个非常缓慢的过程,我觉得这将是更快,如果它做了以下内容:

This is a really slow process and I feel like it would be faster if it did the following:


  1. 编译所有模块

  2. 在所有模块运行单元测试

  3. 在所有模块运行集成测试

有效地做这样的事情:


  1. 执行当前阶段的所有模块

  2. 将进入下一阶段,重复

不过,我想不出如何设置的。这可能吗?或者是我的假设,这可能会更快了吗?感谢您的帮助。

However I can't figure out how to set this up. Is this possible? Or is my hypothesis that this might be faster off? Thanks for the help.

推荐答案

您不能做到这一点,可以考虑以下结构

You can't do that, consider following structure

A (pom)
|
|
|
|
------B (jar)
|     \---C (dependency) 
|
|------C (jar)

在这里B依赖于C,现在你比如你有以下的B和班;分别用C

here B depends on C, now you for example you have following classes in B & C respectively

class B{
 C c;
 public void sayHello(){
    c.sayHello();
 }
}

C

class C {
  public void sayHello(){}
 }

现在你改变C级为

 class C {
  public void sayHello(String name){}
 }

如果你编上的所有阶段,它会从A开始 - C - B(依存关系图),C编译罚款(编译只是编译源和副本类目标/班),现在你正在运行汇编B检查将编译很好,因为它会采取B的旧版本从本地Maven缓存(它仍然有方法没有任何参数)

and if you do compile on all phase it will start from A - C - B (dependency graph), C compiled fine (compile just compiles source and copies classes to target/classes), now you are running compile on B it will compile fine because it will take B's older version from local maven cache (where it still has method without any param)

现在安装发生在C首先与第B它会成功。

now install happens on C first and on B it will go SUCCESSFUL

同样的事情下次尝试将失败,因为B现在会发现不同的方法签名

next attempts of the same thing will fail, because B will now find different method signature

什么是有效的这里是增量构建,但Maven不完全的支持增量构建在真正意义上的在这里看到的是该打开请求

What would be effective here is incremental build, however maven doesn't quite support incremental build in true sense, see here is the open request for that

如果你只想测试执行从构建生命周期,可以使用单独的构建轮廓做saperate

if you want just test executions saperate from build life cycle you can do it using separate build profile

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

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