Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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

First, I'd suggest to work with Maven 3 rather than 2, migration from the latter to the former is really simple (sometimes you can do it without changing anything) and you will notice a high improvement in performance.

Besides, regarding the build order, you should read a bit about the Maven Reactor, the system in charge of processing multi-module projects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top