Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven phase order with mulit-module project?

Forgive me. I'm a noob at Maven.

Here is my maven project directory:

project/
    pom.xml
    moduleA/
    moduleB/
        sub-moduleA/
        sub-moduleB/
        sub-moduleC/
    moduleC/

Of course, within each module and sub-module, they have their own pom.xml. Also, in this example moduleB depends on moduleA and moduleA depends on moduleC. I know in maven there are multiple phases it goes through, but does it take each phase one at a time, or take each module one at a time. Right now, the only three phases I'm concerned with is compile, package, and install.

For example:

Does it do it in Order 1:

compile moduleC
compile moduleA
compile moduleB
package moduleC
package moduleA
package moduleB
install moduleC
install moduleA
install moduleB

Or does it do it in Order 2:

compile moduleC
package moduleC
install moduleC
compile moduleA
package moduleA
install moduleA
compile moduleB
package moduleB
install moduleB

Or does it do it in a totally different order, or am I just completely off in my understanding in maven?

I'm running Maven 2.2.1. Thanks!

like image 210
Rob Avery IV Avatar asked Jan 24 '13 14:01

Rob Avery IV


2 Answers

Order 2 : The reactor detects all the projects, build a sorted list to build the projects in the right order (respecting dependencies), and then builds the projects, following this order.

If A depends on B, you cannot start to build A if B is not totally processed.

like image 140
Samuel EUSTACHI Avatar answered Oct 23 '22 22:10

Samuel EUSTACHI


I don't mean to be snippy, but you should familiarize your self with the maven output. It really does tell you precisely what it's doing. It will tell you precisely the order in which it will build the modules, and then it will tell you precisely the phase / executions that are going on while it builds each.

For instance, here's a simplified built report. First, it tells you what project its building. Then, for each phase there's a report about which mojo execution is occuring. Note that the execution lines start and end with three --- ( this is maven 3; it's different in maven 2 ). And note that it tells you:

  1. the name of the plugin, e.g. maven-clean-plugin
  2. The version of the plugin
  3. The name of the goal on the plugin that's being executed
  4. The name of the execution, e.g. default-clean

Note, all of the executions that are the default binding for the lifecycle phases, i.e. the built in executions, have a name like default-clean where the phase is identified, as well as the fact that it's the default.

[INFO] ------------------------------------------------------------------------
[INFO] Building common-utilities 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.3:clean (default-clean) @ common ---

   SNIP

[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ common ---

   SNIP

[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ common ---

   SNIP

[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ common ---
like image 23
chad Avatar answered Oct 23 '22 23:10

chad