You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Francois Papon <fr...@openobject.fr> on 2020/01/20 19:34:15 UTC

BuildPluginManager NPE

Hi,

I'm using the BuildPluginManager in my custom maven-plugin to execute an
external maven plugin but I have a NPE  in the executeMojo because the
maven session in the external maven plugin is null.

Here an example of the code I'm using:

            PluginDescriptor toolPluginDescriptor =
pluginManager.loadPlugin(toolPlugin,
                    mavenProject.getRemotePluginRepositories(),
                    mavenSession.getRepositorySession());
            MojoDescriptor toolMojoDescriptor =
toolPluginDescriptor.getMojo("assembly");
            MojoExecution execution = new
MojoExecution(toolMojoDescriptor, configuration);
            pluginManager.executeMojo(mavenSession, execution);
//mavenSession is not null

Any ideas?

Thanks!

regards,

-- 
François fpapon@apache.org


Re: BuildPluginManager NPE

Posted by Francois Papon <fr...@openobject.fr>.
Thanks Romain!

I will try this way.

regards,

François
fpapon@apache.org

Le 22/01/2020 à 07:05, Romain Manni-Bucau a écrit :
> Guess you wanted to call MavenPluginManager#getConfiguredMojo or mimic its
> interpolation support:
>
> ExpressionEvaluator expressionEvaluator = new
> PluginParameterExpressionEvaluator(session, mojoExecution);
> this.populatePluginFields(mojo, mojoDescriptor, pluginRealm,
> pomConfiguration, expressionEvaluator);
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://rmannibucau.metawerx.net/> | Old Blog
> <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
> <https://www.packtpub.com/application-development/java-ee-8-high-performance>
>
>
> Le mar. 21 janv. 2020 à 08:13, Francois Papon <fr...@openobject.fr>
> a écrit :
>
>> Hi,
>>
>> I found a workaround by adding the parameter in the configuration:
>>
>> <mavenSession>${session}</mavenSession>
>>
>> However, I don't understand why the default values of the external
>> plugin are not used:
>>
>> @Parameter(defaultValue = "${session}", readonly = true)
>>  protected MavenSession mavenSession;
>>
>> regards,
>>
>> François
>> fpapon@apache.org
>>
>> Le 20/01/2020 à 20:34, Francois Papon a écrit :
>>> Hi,
>>>
>>> I'm using the BuildPluginManager in my custom maven-plugin to execute an
>>> external maven plugin but I have a NPE  in the executeMojo because the
>>> maven session in the external maven plugin is null.
>>>
>>> Here an example of the code I'm using:
>>>
>>>             PluginDescriptor toolPluginDescriptor =
>>> pluginManager.loadPlugin(toolPlugin,
>>>                     mavenProject.getRemotePluginRepositories(),
>>>                     mavenSession.getRepositorySession());
>>>             MojoDescriptor toolMojoDescriptor =
>>> toolPluginDescriptor.getMojo("assembly");
>>>             MojoExecution execution = new
>>> MojoExecution(toolMojoDescriptor, configuration);
>>>             pluginManager.executeMojo(mavenSession, execution);
>>> //mavenSession is not null
>>>
>>> Any ideas?
>>>
>>> Thanks!
>>>
>>> regards,
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: BuildPluginManager NPE

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Guess you wanted to call MavenPluginManager#getConfiguredMojo or mimic its
interpolation support:

ExpressionEvaluator expressionEvaluator = new
PluginParameterExpressionEvaluator(session, mojoExecution);
this.populatePluginFields(mojo, mojoDescriptor, pluginRealm,
pomConfiguration, expressionEvaluator);


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>


Le mar. 21 janv. 2020 à 08:13, Francois Papon <fr...@openobject.fr>
a écrit :

> Hi,
>
> I found a workaround by adding the parameter in the configuration:
>
> <mavenSession>${session}</mavenSession>
>
> However, I don't understand why the default values of the external
> plugin are not used:
>
> @Parameter(defaultValue = "${session}", readonly = true)
>  protected MavenSession mavenSession;
>
> regards,
>
> François
> fpapon@apache.org
>
> Le 20/01/2020 à 20:34, Francois Papon a écrit :
> > Hi,
> >
> > I'm using the BuildPluginManager in my custom maven-plugin to execute an
> > external maven plugin but I have a NPE  in the executeMojo because the
> > maven session in the external maven plugin is null.
> >
> > Here an example of the code I'm using:
> >
> >             PluginDescriptor toolPluginDescriptor =
> > pluginManager.loadPlugin(toolPlugin,
> >                     mavenProject.getRemotePluginRepositories(),
> >                     mavenSession.getRepositorySession());
> >             MojoDescriptor toolMojoDescriptor =
> > toolPluginDescriptor.getMojo("assembly");
> >             MojoExecution execution = new
> > MojoExecution(toolMojoDescriptor, configuration);
> >             pluginManager.executeMojo(mavenSession, execution);
> > //mavenSession is not null
> >
> > Any ideas?
> >
> > Thanks!
> >
> > regards,
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: BuildPluginManager NPE

Posted by Francois Papon <fr...@openobject.fr>.
Hi,

I found a workaround by adding the parameter in the configuration:

<mavenSession>${session}</mavenSession>

However, I don't understand why the default values of the external
plugin are not used:

@Parameter(defaultValue = "${session}", readonly = true)
 protected MavenSession mavenSession;

regards,

François
fpapon@apache.org

Le 20/01/2020 à 20:34, Francois Papon a écrit :
> Hi,
>
> I'm using the BuildPluginManager in my custom maven-plugin to execute an
> external maven plugin but I have a NPE  in the executeMojo because the
> maven session in the external maven plugin is null.
>
> Here an example of the code I'm using:
>
>             PluginDescriptor toolPluginDescriptor =
> pluginManager.loadPlugin(toolPlugin,
>                     mavenProject.getRemotePluginRepositories(),
>                     mavenSession.getRepositorySession());
>             MojoDescriptor toolMojoDescriptor =
> toolPluginDescriptor.getMojo("assembly");
>             MojoExecution execution = new
> MojoExecution(toolMojoDescriptor, configuration);
>             pluginManager.executeMojo(mavenSession, execution);
> //mavenSession is not null
>
> Any ideas?
>
> Thanks!
>
> regards,
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org