the @goal annotation is to be defined in the class javadoc, not in the
execute method javadoc...

Just checkout the code of an existing mojo as an example :)

Regards,

Raphaël

2006/3/17, Mark <[EMAIL PROTECTED]>:
>
> I had a go at creating my first plugin, so I followed:
>
> http://maven.apache.org/guides/plugin/guide-java-plugin-development.html
>
> I aslo looked at:
>
> http://maven.apache.org/developers/mojo-api-specification.html
>
> My problem is that the mojo sections isn't being created in
> META-INF/maven/plugin.xml from the annotated java file so you get a
> java.lang.NullPointerException when you try to invoke the plugin.
>
> Any ideas why this didn't work for me ?
> **
> *Here is what happened:*
>
> 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>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>

Reply via email to