简体   繁体   中英

Maven: Aggregation vs. Dependency

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM