我们可以从它失败的地方开始建造吗

假设,我正在我的大型项目上进行完整的构建,该项目有7个模块,在第6个模块上,由于测试失败,构建失败。有没有什么方法可以让我从失败的地方开始构建?

66665 次浏览

You can resume the build from the 6th module using -rf or --resume-from:

-rf, --resume-from
          Resume reactor from specified project

See the Advanced Reactor Options for details.

you can resume the build from any module you want by using the -rf command. For example, if your build failed in myproject-proxy, you can use the following command:

mvn -rf myproject-proxy clean install

look at the maven summary and you will see the executed modules and where maven is stopped. then try this:

mvn clean install-Dmaven.test.skip=true -rf :yourModule

Here is the example

mvn clean install -rf :your-module

Syntax: mvn -rf modulename mavengoal or mvn --resume-from modulename mavengoal

mvn -rf admin-module clean install or mvn --resume-from admin-module clean install

According to "What's New in Maven 4" (Nov. 2020) from Maarten Mulders, you will soon be able to, with the upcoming Maven 4.0.0 (Q1 2021)

Consider this example project structure:

https://maarten.mulders.it/2020/11/whats-new-in-maven-4/example-project_hu981f14f09d98e6139a671549a98c2057_118421_1037x555_resize_box_2.png

Use --also-make together with --resume-from

The first improvement in the Reactor is a bug fix.
Previously, if your project build failed on the client module, you would get a hint to resume the build with --resume-from :client. But if you did that, the build would break again: this time because Maven couldn’t find the common module.
You might think that adding --also-make (or -am) would address this, but it wouldn’t. This long-standing bug is no longer there.

If you combine --resume-from :client with --also-make, the Reactor will find all modules in your project and continue the build as you requested.

Automatically resume from the last point of failure

But chances are you will not notice. The thing with --resume-from :client is that it makes you think more than necessary.

With Maven 4, you can make your life even easier and use --resume, or -r for short. It will automatically resume the build from the module that last failed.

But there’s more! Maybe you are using parallel builds. One sequence of modules was successfully built, while the build of another sequence of modules broke.
In that scenario, using -r will skip the modules that were successful in the previous build.

The combination of these two features may well improve the time you need to build your large, enterprise software project!