views:

147

answers:

1

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.

+4  A: 

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.

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