Hi there,
I have developed a plugin which can execute other Maven plugins depending on
certain properties available in a project.
The process is like this:
1. Maven build starts
2. Plugin A is triggered which has several executions defined. Depending on
properties in the project on hand a execution is triggered
3. Plugin B (or C, D etc) will be triggered.
The problem is I do not have access to the MavenProject and MavenSession in
Plugin B (or C, D) because these are not injected resulting in
NullPointerExceptions. The BuildPluginManager however is correctly injected
(however not needed in this plugin but added it to test the mechanism).
I'm using the same syntax in Plugin A and there both MavenProject and
MavenSession are injected.
Some code examples:
Plugin A executing other plugins:
----------------------------------------
private void executePlugin ( Plugin plugin, String executionId, String
goal ) throws MojoExecutionException
{
try
{
List<RemoteRepository> repositories =
session.getCurrentProject().getRemoteProjectRepositories();
MojoDescriptor mojoDescriptor =
pluginManager.getMojoDescriptor(plugin, goal, repositories,
session.getRepositorySession());
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor,
executionId );
getLog().info( "Executing goal " + goal + " within execution " +
executionId + " for plugin " + plugin );
pluginManager.executeMojo(session , mojoExecution);
}
catch ( Exception e )
{
throw new MojoExecutionException( "Error executing plugin " +
plugin + " with execution id " +
executionId, e );
}
}
Plugin B
----------------
/**
* Goal which updates the VersionIF.java with the current version.
* @goal updateVersion
* @phase process-sources
*
*/
public class VersionIFMojo extends AbstractMojo {
/**
* The Maven project.
*
* @parameter expression="${project}"
*/
private MavenProject project;
/**
* The Maven Session Object
*
* @parameter expression="${session}"
* @readonly
*/
protected MavenSession session;
/**
* Plugin manager used to invoke plugin executions.
*
* @required
* @component
*/
private BuildPluginManager pManager;
<...>
All worked well when using Maven 2 but after migrating to Maven 3 builds
stopped working.
Can somebody help me resolving this issue?
Thank you
Kind regards,
Richad
--
View this message in context:
http://maven.40175.n5.nabble.com/MavenProject-MavenSession-not-injected-when-executing-plugin-from-a-plugin-tp5716570.html
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]