开发者

Running unit tests before building stage in multi-module maven project

开发者 https://www.devze.com 2023-04-08 11:27 出处:网络
I have a multi-module maven project. In every module there are unit tests. When I make clean install tests run befo开发者_如何学Cre every module and if all tests in one module are success it build suc

I have a multi-module maven project. In every module there are unit tests. When I make clean install tests run befo开发者_如何学Cre every module and if all tests in one module are success it build successfully. If one test failure all other tests in that module run successfully (or some run successfully, other failed). The build of module in what the first failure unit test is placed failed. Other modules are skipped. I want such thing: first to run all unit tests in all modules, and after that if there is no failed tests build all modules, or if there is one or more failed tests in one or mode modules skip building of all modules. Can you help me with it?


run:

mvn clean test
mvn install -Dmaven.test.skip=true

note, if you have inter-module dependencies (which i assume you do), you probably can't really do this, as you will need to build the dependent jars before you can run the tests in the other module.


AFAIK its impossible in maven. You are trying to change a maven build lifecycle which is not allowed in maven. However there are a couple of configuration parameters you can pass to maven and this will affect the testing.

mvn install -Dmaven.test.skip

This won't run unit tests at all

mvn install -Dmaven.test.failure.ignore=true 

This will cause maven to not stop and proceed the module building process even if there were failures during the test phase. Hope, this helps


The problem is:

the modules probably have dependencies upon each other, and to resolve those dependencies, you have to build the modules in order, or they won't compile. So there's no sane solution to your problem.

Insane solutions would somehow aggregate the sources (and external dependencies) from all child projects and run compile and test on that conglomerate, but it would be such a monstrous hack that I'm glad they didn't do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消