views:

61

answers:

1

When creating a plugin that executes in the default life-cycle, it's easy to obtain a reference to the project and its resources, but I'm getting a null instead of a MavenProject object when creating plugins that execute in the site life-cycle.

Any hints, tips or suggestions?

+1  A: 

It turns out the problem I was having was related to my declaration of the Project parameter being passed into my Mojo. Since there's only one instance of a MavenProject within a Maven build, you can't specify an expression (and there's really no Java String that can be cast to a MavenProject object) for the parameter and the default value has to be "${project}".

So to access the MavenProject from within a Maven Plugin Mojo, for any phase, use the following parameter declaration:

/**
 * Project instance, used to add new source directory to the build.
 * 
 * @parameter expression="export.project" default-value="${project}"
 * @required
 * @readonly
 */
private MavenProject project;
Steve Moyer