Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I execute several maven plugins within a single phase and set their respective execution order?

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?

like image 265
Yaneeve Avatar asked Mar 24 '10 16:03

Yaneeve


People also ask

Are Maven plugins executed in order?

Plugin executions are ordered according to their phases.

What is Maven plugin execution?

Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process. exec:java - can be used to run a Java program in the same VM.

What is the correct syntax for executing a Maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”.

What are the two types of Maven plugins?

Introduction. In Maven, there are two kinds of plugins, build and reporting: Build plugins are executed during the build and configured in the <build/> element. Reporting plugins are executed during the site generation and configured in the <reporting/> element.


2 Answers

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).

like image 51
Pascal Thivent Avatar answered Oct 02 '22 04:10

Pascal Thivent


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

like image 37
rperez Avatar answered Oct 02 '22 04:10

rperez