On Nov 10, 2010, at 12:46 AM, Christopher Hunt wrote:

> Thanks Oliver.
> 
> I think that it'll be quite a while before people write MOJOs just for Maven 
> 3. From my own perspective having just written two new MOJOs, I'd like to be 
> able to write for the future but recognise the present. It'd be great to use 
> @inject in my code now and then use the MOJO with Maven 2. Not possible?
> 

Not impossible, but a huge amount of work to get to work in Maven2  and I'm not 
aware of anyone doing any work in this area to make JSR-330 work in Maven 2. 
But it's definitely within the realm of possibility in Maven 3.

> I really find Plexus tricky to work with given the lack of documentation and 
> would prefer to use JSR-330 (as Maven 3 itself does!).
> 

Maven itself does not use JSR-330, it uses Guice with a adapter layer to run 
Plexus components within Guice. But a plugin that uses JSR-330 might possibly, 
maybe,  look something like this:

@Goal( "webxml" )
@Phase( GENERATE_RESOURCES )
@RequiresProject
@Threadsafe
public class GenerateWebXml extends SonatypeMojo {
    @Inject 
    Logger logger;
    
    @Inject
    private StreamingArchiver component;
    
    @Inject @Named( "${project}" )
    private MavenProject project;
    
    @Inject @Named( "${outputDirectory}" ) @DefaultsTo( 
"${project.build.directory}" )
    private File outputDirectory;
    
    @Inject
    private List<WebXmlAugmenter> webXmlAugmenters;
    
    public void execute() throws Exception {
        component.generate( project, webXmlAugmenters, outputDirectory );
    }
}

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
http://twitter.com/jvanzyl
---------------------------------------------------------

happiness is like a butterfly: the more you chase it, the more it will
elude you, but if you turn your attention to other things, it will come
and sit softly on your shoulder ...

 -- Thoreau 



Reply via email to