Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven use @component to inject a mojo

Tags:

maven-2

i've a maven plugin composed of some mojos. Suppose there is myproject.FirstMojo declared as @goal first and myproject.SecondMojo declared as @goal second

what I want to do is inject first mojo as property of second mojo. What I've tried is declare it the following way :

/**
 * @component role="myproject.FirstMojo"
 */
private FirstMojo first;

Unfortunatly, when doing so, I get a Component descriptor cannot be found in the component repository: error.

What should I do ?

like image 960
Riduidel Avatar asked Oct 25 '22 19:10

Riduidel


1 Answers

You can use:

/** @component role="org.apache.maven.plugin.Mojo" role-hint="groupId:artifactId:version:second" */
private FirstMojo first;

Note that they have to be in the same plugin, and you must replace the group, artifact and version with your values. This will likely involve filtering your source code for the correct version, which makes it a bit complicated.

I would highly recommend factoring out the functionality you need into a separate class (perhaps a Plexus component if you need access to some components in there), or an abstract base class.

like image 134
Brett Porter Avatar answered Nov 17 '22 10:11

Brett Porter