13

I'm very new to Maven and am just now trying to set up my first project tree. I'm struggling to understand the difference between two alternatives:

I have jar and war projects (two each) that i want to bundle. Traditionally I'd just create an ear project that has all four of them as dependencies.

Now I read about the aggregation of poms and am not sure what to do any more (see http://maven.apache.org/pom.html#Aggregation). Should I create an aggregateted POM with the four projects?

I guess basically my question is: What's the big difference between a module and a dependency, if the dependency is one of my "own" projects.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
apropoz
  • 327
  • 1
  • 3
  • 9
  • the convention at SO is to use the tag maven-2, unless you're referring to the (dead) maven version 1. It's a nuisance, if you ask me, but that's the way it is. Changed that for you. – Sean Patrick Floyd Jul 27 '10 at 12:58

1 Answers1

11

A module is just a way of organizing things.

In a multi-module build, you can build an entire tree of artifacts in one step (remember the Joel Test). However, each of these will be an individual artifact, which can individually be referenced as a dependency.

Here is a sample layout, packaging in parentheses.

root (pom)
    - project1 (jar)
    - project2 (war) -> references project1 as dependency
    - project3 (jar)
    - project4 (war) -> references project3 as dependency
    - project5 (ear) -> references project2 and project4 as dependency

call mvn install in the root directory to build the entire tree.

The assumption here is that project1 is only used by project2 and project3 is only used by project4. Otherwise here is a more complex scenario.

root (pom)
    - project1 (jar)
    - project2 (jar)
    - project3 (war) -> references project1 and project2 as dependency of scope provided
    - project4 (war) -> references project1 and project2 as dependency of scope provided
    - project5 (ear) -> references project1 through project4 as dependency

So, modules take away the work of building several projects independently, but you still need to manage your dependencies yourself.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • 2
    Thanks for your answer! Just to make it clear: If, in your example, I would not use a 'root' project but would just build project5 (i.e. 'mvn install' there), then it would _not_ automatically recompile projects 1-4, right? I guess that's what I falsely assumed and what lead to my confusion. – apropoz Jul 27 '10 at 13:08
  • exactly. maven works nowhere but underneath the current directory. it will resolve other artifacts from the local or remote repository, but it will not re-build them unless they are inside the current tree. – Sean Patrick Floyd Jul 27 '10 at 14:35