Chapter 3. Multiproject Maven

In Section 1.1 you saw how you can create and build a simple project with a single class. In real life, projects are always more complex, and your projects may need to generate several artifacts (JARs, WARs, EARs, Web Start applications, etc.). Along with multiple artifacts, you will need to perform different build operations for different types of artifacts; for example, EAR files must be packaged for J2EE applications, some projects may include automated functional tests, applications may need to be deployed to an application server, or a project may need to execute a Web Start application. This list could go on forever, and it seems that the longer a project exists, the more complex build requirements become. In Maven, you manage build entropy by splitting a single monolithic monster project into smaller, more manageable subprojects.

Dividing and Conquering

When developing object-oriented code, it is good practice to implement a separation-of-concerns strategy. In a complex software engineering effort, you manage complexity by organizing logic into components which are tightly focused (or concerned) with a specific part of a project or process. You can apply this same idea to a project's build. If you have a huge, multi-artifact project, having a big build with everything stuffed in is asking for maintenance hell. Fortunately, Maven is here to help us break down our project into subprojects.

How do I do that?

Let's take a web application example. Imagine ...

Get Maven: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.