Set Up A Big Maven Project Quickly with Nested Archetypes
Summary
Creating a properly-nested maven project is easy once you know that the archetype builder recognizes parent POMs and creates child modules linked automatically to the parent.
Motivation
Starting a large new maven project has historically been a fair amount of work. Sometimes I copy from an existing multi-module project, doing lots of renaming in the POM files by hand. Other times I'll start from scratch, carefully checking the child POMs reference the parent properly. However, there's a better way
Nested Archetypes
First, create your parent module and its POM. Start in the folder holding your other projects, and run this command to create a starter parent POM:
mvn archetype:generate \
-DarchetypeGroupId=org.codehaus.mojo.archetypes \
-DarchetypeArtifactId=pom-root \
-DarchetypeVersion=RELEASE
Second, go into the newly created folder, and use your archetypes of choice to create the child modules. For a Full Stack Java project, you'll want modules like these:
- ui-web: The Flavour Java SPA front-end
- resource: The JAX-RS service implementation
- api: The JAX-RS service definition / interface
- db: The database access layer
- model: The POJOs
- logic: Shared logic
For each, find the appropriate maven archetype, and run a command like the following, substituting the right coordinates. This example is for the Flavour module:
mvn archetype:generate \
-DarchetypeGroupId=com.frequal.flavour \
-DarchetypeArtifactId=teavm-flavour-application \
-DarchetypeVersion=0.3.0
And for the model and other JAR-style modules:
mvn archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=RELEASE
References
Last modified on 4 Jul 2024 by AO
Copyright © 2024 Andrew Oliver