当JAR已经存在时,为什么Maven再次运行测试? [英] Why Maven is running tests again, when JAR is already there?

查看:85
本文介绍了当JAR已经存在时,为什么Maven再次运行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

install我的Maven项目:

I install my maven project:

mvn clean install

一切正常,在/target目录中创建了JAR文件.现在,我再次运行它:

Everything works fine, JAR file is created in /target directory. Now I run it again:

mvn install

Maven再次执行单元测试和静态代码分析.我没有对.java文件进行任何更改,并且JAR在那里,所以为什么要再次运行测试?我是在做错什么还是Maven的设计方式?

Maven executes unit tests and static code analysis again. I didn't make any changes to the .java files and JAR is there, so why running tests again? Am I doing something wrong or is it how maven is designed?

推荐答案

现在,我再次运行它(...)Maven执行单元测试,并再次静态代码分析

因为这就是您要Maven执行的操作.

Because that's simply what you're asking Maven to do.

当您调用构建阶段时,Maven不仅将执行该构建阶段,还将执行被调用构建阶段之前的每个构建阶段.因此,调用:

When you call a build phase, Maven will execute not only that build phase, but also every build phase prior to the called build phase. Thus, invoking:

mvn install

在执行install以及绑定到这些阶段的插件之前,

将在install之前的每个构建阶段(validatecompiletestpackage等)运行.

will run every build phase preceding install (validate, compile, test, package, etc), before executing install and also the plugins you bound to these phases.

尽管Maven确实支持Java源代码的增量 compilation ,但其他插件并不那么聪明,将再次被触发.

And while Maven does support incremental compilation of Java sources, other plugins are not that smart and will be fired again.

现在,一些评论/建议:

Now, some remarks/suggestions:

  • 如果不进行任何更改,运行install的意义何在?
  • 如果您不想在每次构建时都进行静态代码分析,请使用特殊的配置文件.
  • what's the point of running install if you didn't change anything?
  • if you don't want to run static code analysis at each build, use a special profile.

一个多模块项目,具有广泛的测试和静态代码分析.我运行mvn clean install,然后在一个模块中更改一个Java文件.然后,我运行mvn install,并期望maven仅测试/分析此已更改的特定模块.不幸的是,它会重新测试并重新分析所有模块.

A multi-module project, with extensive testing and static code analysis. I run mvn clean install, then I change one single java file in one module. Then I run mvn install and expect maven to test/analyze only this particular module, which was changed. Unfortunately, it re-tests and re-analyzes all modules.

的确,如果您在反应堆构建中运行mvn install,则将在所有模块上运行mvn install,并且将在所有模块上再次进行测试和分析.也许这不是您所期望的,但那是您将得到的(AFAIK,静态分析插件不知道更改-我无法解释为什么情况不会更好).

Indeed, if you run mvn install as part of a reactor build, will run mvn install on all modules and tests and analysis will go again on all modules. That's maybe not what you expect, but that's what you'll get (AFAIK, static analysis plugin are not aware of changes - I'm not able to explain why things aren't better).

需要很多时间.

It takes so much time.

我建议使用 the先进的反应堆选项以仅构建模块的子集.这些选项是:

I suggest to use the advanced reactor options to only build a subset of the modules. These options are:

-rf, --resume-from
        Resume reactor from specified project
-pl, --projects
        Build specified reactor projects instead of all projects
-am, --also-make
        If project list is specified, also build projects required by the list
-amd, --also-make-dependents
        If project list is specified, also build projects that depend on projects on the list 

因此,在您的情况下,您可以运行类似的命令(假设您触摸了module-foo):

So in your case, you could run something like (assuming you touched module-foo):

mvn -pl module-foo,my-packaged-app install

或重建所有依赖module-foo的项目:

or, to rebuild all projects that depend on module-foo:

mvn -pl module-foo -amd install

这篇关于当JAR已经存在时,为什么Maven再次运行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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