This document describes how to create a simple Maven plugin called "firstMojo" that contains a goal called "sayhi". It discusses creating the plugin project structure with a pom.xml and Java class, installing the plugin, and invoking the "sayhi" goal from another Maven project which prints a customized greeting message.
1 of 9
Download to read offline
More Related Content
My First MOJO Plugin
1. My First MOJO Plugin
Tibor Diga¨¾a
Github repository
https://github.com/Tibor17/maven/tree/master/plugins/firstMojo
4. Locations of files
? If your plugin pom.xml is located in ${basedir},
then place the java source class
sample.plugin.MyMojo
in to
${basedir}/src/main/java
7. Running the plugin¡¯s goal sayhi on
another pom.xml
mvn sample.plugin:hello-maven-plugin:1.0:sayhi
8. Running the plugin¡¯s goal sayhi on
another pom.xml
[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------
[INFO] Building my plugin usage
[INFO] task-segment: [sample.plugin:hello-maven-plugin:1.0:sayhi]
[INFO] -------------------------------------------------------------
[INFO] [hello:sayhi {execution: default-cli}]
[INFO] Hi There!
[INFO] base dir c:Userstibor17IdeaProjectsfirstMojopluginUsage
[INFO] -------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Fri Jun 15 13:47:40 CEST 2012
[INFO] Final Memory: 2M/15M
[INFO] -------------------------------------------------------------
9. Running the plugin¡¯s goal sayhi on
another pom.xml
? Logger printed ¡°Hi There!¡±
? instead of default-value "Hello World!¡°
? See the field ¡°greeting¡± in MyMojo class