111

Suppose, I am doing a full build on my large project which has 7 modules and on the 6th module, the build failed because a test failed. Is there any way by which I can start the build from the point it failed?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Shekhar
  • 5,771
  • 10
  • 42
  • 48

6 Answers6

154

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.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 1
    this is good, for sub-subprojects just use `subproject/subsubproject` as a parameter – akostadinov Jan 20 '14 at 08:17
  • 16
    Example: `maven -rf clean install` – Zoltán Oct 02 '14 at 12:34
  • 11
    This only worked for me when I prepended the module name with a colon, e.g. `mvn -rf :moduleName install`. (Not sure exactly why the colon is needed but it seems to be - at least for my setup.) – Steve Chambers Jun 12 '15 at 09:58
  • 7
    Looks like this only works if your initial build had an `install` goal in it, because the resuming build can then get the artifacts that were already built from your local Maven repository to resolve dependencies on them. I find it bad practice to run `install` builds as you end up cluttering your local repository with snapshots and you may end up depending on an older snapshot than what you expect. Looks like for builds where you only `package` and don't `install`, using `-rf` is not an option: you'll have to do the entire build. – Frans Aug 29 '16 at 12:00
  • 1
    I agree with Frans. I never use the install goal and always stick to "package" or at most "verify" when on my development machine. I wish there was a way to use -rf and have the reactor just use target/classes from previous projects instead of requiring that the output be present in your local repository... – Alexandros Apr 02 '18 at 23:47
  • Would it resume even after ctrl+c? – Nilotpal Nov 20 '19 at 07:27
  • What exactly is "module name"? project name? Artifact id? jar name? – Joker Mar 23 '21 at 13:56
24

Here is the example

mvn clean install -rf :your-module
M Sach
  • 33,416
  • 76
  • 221
  • 314
9

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
Rahul Gupta
  • 9,775
  • 7
  • 56
  • 69
user3401235
  • 91
  • 1
  • 3
9

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
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Antonio Martin
  • 361
  • 3
  • 12
3

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!

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • hello @VonC , im asking off topic question. i want to know which soft-wares do you maintain? i have seen jira ,git ,maven etc. on your profile page are you contributor? and how come you know so much about git? and do you build them? im curious... – nikhil swami Dec 21 '20 at 05:02
  • 1
    @nikhilswami I maintain a few tool I am using at work (https://github.com/VonC). And I learned Git by answering questions on Stack Overflow back in 2009. Nowadays, I am actively supporting developer teams using Git, so I continue to learn that way too. – VonC Dec 21 '20 at 07:25
-1

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

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

scott_dennis
  • 77
  • 1
  • 7