Creating a multi-module Maven project

A multi-module Maven project aggregates several Maven projects into a single one. In this chapter, we will create three modules that form the whole application:

  • webapp: A Vaadin web application packaged as a WAR file that includes everything needed to deploy it to a server such as Tomcat, Wildfly, Jetty, or any other Java server
  • api: A Java API packaged as a JAR used by the webapp and any functional module
  • example-module: An example functional module that uses the api JAR to add functionality to the application

All these modules are aggregated into a single Maven project with the name chapter-02. Let's start by creating this aggregator project by using the pom-root Maven archetype. Run the following in a terminal:

mvn archetype:generate \
-DarchetypeGroupId=org.codehaus.mojo.archetypes \
-DarchetypeArtifactId=pom-root \
-DarchetypeVersion=RELEASE

Use the following properties when prompted:

  • groupId: packt.vaadin.datacentric
  • artifactId: chapter-02
  • version: 1.0-SNAPSHOT
  • package: packt.vaadin.datacentric.chapter02

When using this archetype, Maven generates a pom.xml file for a top-level multi-module or aggregator project. You can remove the <name> tag as it’s redundant for our purposes. Modify the file to include a property for the Vaadin version:

<project xmlns="…" xsi:schemaLocation="…">
<modelVersion>4.0.0</modelVersion>

<groupId>packt.vaadin.datacentric</groupId>
<artifactId>chapter-02</artifactId>
<version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

<properties>
<vaadin.version>8.3.2</vaadin.version>
</properties>
</project>
Note that in the code provided with this book, you'll find a <parent> section in the pom.xml file of the chapter-02  project. This is because all the demo applications of the book have been aggregated into a single Data-centric-Applications-with-Vaadin-8 Maven project for your convenience. You don’t need to add any <parent> sections to your project if you are following the steps in this chapter.

This project (chapter-02) can be seen as the root directory for a full-blown application that contains several Maven modules, each one dedicated to a specific aspect of the functionality of the system.