Creating Custom Top-Level Goals
Now let's build the QOTD web application using our master project. Hold
on! What does it mean to build the QOTD web application? Each subproject
has its own definition of build: for the core
subproject it means calling the jar:install
goal, for the web
subproject it means calling the war:install
goal, etc. You need to define some
common goals in your subprojects that you can call from your master
project.
How do I do that?
You can do this easily, by creating a maven.xml file in each subproject and
defining a custom goal in there. Let's call this goal qotd:build
. Here's what you would put in the
core/maven.xml file:
<?xml version="1.0"?> <project default="qotd:build"> <goal name="qotd:build" prereqs="jar:install"/> </project>
The same applies for the other subprojects. For example, for the
web
subproject, you'll
write:
<?xml version="1.0"?> <project default="qotd:build"> <goal name="qotd:build" prereqs="war:install"/> </project>
Note
To manage different types of subproject builds, define the same custom goal in each subproject and use the Multiproject plug-in to execute it.
Now that each subproject has a qotd:build
goal that builds it, you can also
create a qotd:build
goal in the
master project's maven.xml file.
This goal uses the Multiproject plug-in to call the qotd:build
goal on all the subprojects:
<?xml version="1.0"?> <project default="qotd:build" xmlns:j="jelly:core"> <goal name="qotd:build"> <j:set var="goal" value="qotd:build"/> <attainGoal name="multiproject:goal"/> ...
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.