17

I would like to breakup certain phases in the maven life cycle into sub phases. I would like to control the execution flow from one sub-phase to another, sort of like with ant dependencies.

For example, I would like to use the NSIS plugin in order to package up my project into an installer at the package stage, AFTER my project had been packaged into a war file. I would like to do all that at the package phase.

Is that possible?

2
  • Doesn't Maven execute plugin goals bound to the same lifecycle phase in the order they are listed in the pom? Just a guess, may be worth testing... Mar 24, 2010 at 16:47
  • Don't know... I'll give it a try
    – Yaneeve
    Mar 24, 2010 at 17:12

2 Answers 2

13

Plugins bound to the same phase should be executed in the same order as they are listed in the POM. Under certain circumstances (e.g. if you bind the same plugin to a phase twice, like the antrun plugin), this may not occur but this is a bug (see MNG-2258 and the related issue MNG-3719).

6
  • but what if you specify them in unrelated blocks, such as the normal build block vs. a build block that's part of a profile block? There may be some plugins in the profile block that should run after those in the plugins block, but others may not.
    – mxk
    Nov 2, 2011 at 10:37
  • 9
    This doesn't happen (at least in maven 3.0.4). I have two plugins with executions bound to generate-sources, one listed first in the list of about 6 plugins and the other listed last. However, the one listed last (which depends on the one listed first) always executes first.
    – matt5784
    May 23, 2012 at 18:32
  • Agree with matt5784, this is annoying :( Jul 27, 2012 at 23:51
  • 1
    Work around: sort by desired order and reverse. Tested and works for me :)
    – Dormouse
    Apr 7, 2014 at 11:33
  • 1
    The bugs listed are purportedly fixed in Maven 3.0.3. mkyong.com/maven/maven-plugin-execution-order-in-same-phase Jul 11, 2014 at 14:58
6

I had the same problem. look at How to perform ordered tasks in Maven2 build. for some reason the different goals bound to a phase are stored in a hash map or other unordered structure which makes the execution order random. my solution was to spread the tasks to different phases but I dont think there is much sence for it in your case (nsis packaging is not pre integration test). you could do one of the following:

1) try your luck and see if Maven chosses the right order for you (you probably tried that already)

2) use standalone plugin - run the goal outside the lifecycle. something like: mvn package org.codehaus.mojo:nsis-maven-plugin:1.0:compile.

3) separate them into module: have a parent pom containing two sub modules, one - your war project and the other for the nsis project.

4) use a custom lifecycle by changing the type, in your case you can use "exe". this is done by using a custom plugin extension (guide to using extension)

5) use the jetspeed-mvn-maven-plugin. I have never used it but it seems relevant to your needs.

hope this gives you new ideas.

Ronen

2
  • Thanks, but except for some "kinks" with the default lifecycle @Pascal is right
    – Yaneeve
    Mar 25, 2010 at 9:21
  • 1
    those are no "kinks". actually if you ask the Maven guys they'll tell you that number 3 is with best accordance with the "Maven way" that is the separation of modules and when you think about it, it make a lot of sense that creating a web application and an installer project are two separate things.
    – rperez
    Mar 25, 2010 at 11:44

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.