How do I create a hello world goal for a maven plugin?
Author: Deron Eriksson
Description: This tutorial describes how to create a hello world goal for a maven plugin.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


Page: < 1 2

(Continued from page 1)

Now let's install the plugin into our local mavenSW repository so that we can use it. I'll perform a "mvn clean install" on the "maven-howdy-plugin" project.

Executing 'mvn clean install' on 'maven-howdy-plugin'

The console output is shown here.

Console output of 'mvn clean install' on 'maven-howdy-plugin' project

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Howdy Plugin
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\dev\workspace\maven-howdy-plugin\target
[INFO] [plugin:descriptor]
[INFO] Using 2 extractors.
[INFO] Applying extractor for language: java
[INFO] Extractor for language: java found 1 mojo descriptors.
[INFO] Applying extractor for language: bsh
[INFO] Extractor for language: bsh found 0 mojo descriptors.
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to C:\dev\workspace\maven-howdy-plugin\target\classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [surefire:test]
[INFO] No tests to run.
[INFO] [jar:jar]
[INFO] Building jar: C:\dev\workspace\maven-howdy-plugin\target\maven-howdy-plugin-1.0-SNAPSHOT.jar
[INFO] [plugin:addPluginArtifactMetadata]
[INFO] [install:install]
[INFO] Installing C:\dev\workspace\maven-howdy-plugin\target\maven-howdy-plugin-1.0-SNAPSHOT.jar to \dev\m2repo\com\maventest\maven-howdy-plugin\1.0-SNAPSHOT\maven-howdy-plugin-1.0-SNAPSHOT.jar
[INFO] [plugin:updateRegistry]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Mon Feb 18 15:48:50 PST 2008
[INFO] Final Memory: 11M/21M
[INFO] ------------------------------------------------------------------------

Now, we can call the goal from any maven project. I'll go to the maven-howdy-plugin project itself and then call it via "mvn com.maventest:maven-howdy-plugin:howdy-world"..

mvn com.maventest:maven-howdy-plugin:howdy-world

As you can see from the output, the howdy-world goal is executed successfully. The console output from executing the goal is also included here:

Console output of 'mvn com.maventest:maven-howdy-plugin:howdy-world'

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Howdy Plugin
[INFO]    task-segment: [com.maventest:maven-howdy-plugin:howdy-world]
[INFO] ------------------------------------------------------------------------
[INFO] [howdy:howdy-world]
[INFO] Hi there!!!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Mon Feb 18 15:54:23 PST 2008
[INFO] Final Memory: 1M/4M
[INFO] ------------------------------------------------------------------------
Page: < 1 2