package jms.maven.first.mojo;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
public class GreetingMojo extends AbstractMojo
{
/**
* @goal sayhi
* @description Says "Hi" to the user
*/
public void execute() throws MojoExecutionException, MojoFailureException
{
getLog().info("Hello, world.");
}
}
I made sure the <packaging>maven-plugin</packaging> was in the pom, before I ran mvn install:
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Sample Parameter-less Maven Plugin
[INFO] task-segment: [install]
[INFO] ----------------------------------------------------------------------------
[INFO] [plugin:descriptor]
[INFO] Using 2 extractors.
[INFO] Applying extractor for language: java
[INFO] Extractor for language: java found 0 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] Nothing to compile - all classes are up to date
[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: E:\java\work\workspaces-3.1.2\default\jms.maven.first.mojo\targe
[INFO] [plugin:addPluginArtifactMetadata]
[INFO] [install:install]
[INFO] Installing E:\java\work\workspaces-3.1.2\default\jms.maven.first.mojo\target\m
[INFO] [plugin:updateRegistry]
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Fri Mar 17 08:41:15 GMT 2006
[INFO] Final Memory: 5M/10M
[INFO] ----------------------------------------------------------------------------
I suppose the important bits are:
[INFO] Extractor for language: java found 0 mojo descriptors.
[INFO] Applying extractor for language: bsh
[INFO] Extractor for language: bsh found 0 mojo descriptors.
Sure enough if you try to invoke the plugin you get:
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ----------------------------------------------------------------------------
[INFO] null
[INFO] ----------------------------------------------------------------------------
[INFO] Trace
java.lang.NullPointerException
at org.apache.maven.plugin.descriptor.PluginDescriptor.getMojo
(PluginDescriptor.java:261)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1363)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds
(DefaultLifecycleExecutor.java:376)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:132)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:316)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:113)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke
(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode
(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Fri Mar 17 08:45:46 GMT 2006
[INFO] Final Memory: 1M/2M
[INFO] ----------------------------------------------------------------------------
Delving into the plugin jar META-INF/maven/plugin.xml file you find:
<plugin>
<description></description>
<groupId>javamark</groupId>
<artifactId>maven-hello-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<goalPrefix>hello</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<mojos/>
<dependencies/>
</plugin>
First off I am not sure where <goalPrefix>hello</goalPrefix> comes from I would have thought this should be <goalPrefix>sayhi</goalPrefix> .
The workaround was to manually create the mojo section as:
<mojos>
<mojo>
<goal>sayhi</goal>
<requiresProject>true</requiresProject>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<implementation>jms.maven.first.mojo.GreetingMojo</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
</mojo>
</mojos>
<project> <modelVersion>4.0.0</modelVersion> <groupId>javamark</groupId> <artifactId>maven-hello-plugin</artifactId> <packaging>maven-plugin</packaging> <version>1.0-SNAPSHOT</version> <name>Sample Parameter-less Maven Plugin</name> <build> <sourceDirectory>src/main/java</sourceDirectory> <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory> <testSourceDirectory>src/test/java</testSourceDirectory> <directory>target</directory> <outputDirectory>target/classes</outputDirectory> <testOutputDirectory>target/test-classes</testOutputDirectory> </build> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>2.0</version> </dependency> </dependencies> </project>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]