Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

The Maven 2 POM demystified

The evolution of a project model

  • Print
  • Feedback

Page 2 of 7

 <project>
  <modelVersion>4.0.0</modelVersion>

<!-- POM Relationships --> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version> <parent>...</parent> <dependencyManagement>...</dependencyManagement> <dependencies>...</dependencies> <modules>...</modules>

<!-- Project Information --> <name>...</name> <description>...</description> <url>...</url> <inceptionYear>...</inceptionYear> <licenses>...</licenses> <developers>...</developers> <contributors>...</contributors> <organization>...</organization>

<!-- Build Settings --> <packaging>...</packaging> <properties>...</properties> <build>...</build> <reporting>...</reporting>

<!-- Build Environment --> <!-- Environment Information --> <issueManagement>...</issueManagement> <ciManagement>...</ciManagement> <mailingLists>...</mailingLists> <scm>...</scm> <!-- Maven Environment --> <prerequisites>...</prerequisites> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <distributionManagement>...</distributionManagement> <profiles>...</profiles> </project>


POM relationships

Our first order of business is to investigate project relationships, represented in Figure 2 as the top-left corner of the chart in Figure 1.

Figure 2. POM relationships

Projects must relate to each other in some way. Since the creation of the first assemblers, software projects have had dependencies; Maven has introduced more forms of relationships hitherto unused in such a form for Java projects. These relationships are Maven coordinates, coordinate-based dependencies, project inheritance, and aggregation.

Coordinates

Each Maven project contains its own unique identifier, dubbed the project's coordinates, which acts like an artifact's address, giving it a unique place in the Maven universe. If projects had no way of relating to each other, coordinates would not be needed. That is, if a universe had just one house, why would it need an address like 315 Cherrywood Lane?

The code below is the minimum POM that Maven 2 will allow—<groupId>, <artifactId>, and <version> are all required fields. They act as a vector in Maven space with the elements grouper, identifier, and timestamp.

 <project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>a</artifactId>
  <version>1</version>
</project>



In the Maven world, these three main elements (The Maven trinity—behold its glory!) make up a POM's coordinates. The coordinates are represented by Figure 3.

Figure 3. A discrete Maven unit

Perhaps this POM is not so impressive by itself. It gets better.

Dependencies

One of the most powerful aspects of Maven is its handling of project dependencies, and in Maven 2, that includes transitive dependencies. Figure 4 illustrates how we shall represent them graphically.

Figure 4. Project dependencies

Dependency management has a long tradition of being a complicated mess for anything but the most trivial of projects. "Jarmageddon" quickly ensues as the dependency tree becomes huge, complicated, and embarrassing to architects who are scorned by new graduates who "totally could have done it better." "Jar Hell" follows, where versions of dependencies on one system are not quite the same versions as those used for development; they have either the wrong version or conflicting versions between similarly named JARs. Hence, things begin breaking and pinpointing why proves difficult. Maven solves both of these problems by having a common local repository from which to link to the correct projects, versions and all.

  • Print
  • Feedback

Resources