Dependency injection in maven plugin

I am developing a maven plugin and making it more testable. I would like to use a lightweight dependency injection environment (like Guice) to manage services, etc., but so far I can get them to integrate with applications that I was not able to integrate with my plugin. Is there a way to do this, saving for doing dependency injection in a static way?

+4
source share
2 answers

Maven already provides you with an integrated IoC container called Plexus. You can enable other components

public class MonitorMojo
    extends AbstractMojo
{

    /**
     * The website monitor component instance that will be injected 
     * by the Plexus runtime.
     * @component
     */
    private WebsiteMonitor monitor;

    public void execute()
        throws MojoExecutionException, MojoFailureException
    {
        // TODO Auto-generated method stub

    }

}

and refer to the properties

@Parameter( property = "sayhi.greeting", defaultValue = "Hello World!" )
private String greeting;

maven plugin dev .

+1

( ), CDI Maven, , carlosvin (Maven JSR 330).

: Maven CDI Plugin Utils.

DI, , .

, , . Btw. DI, CDI, Weld SE bean classpath!

0

Source: https://habr.com/ru/post/1529712/


All Articles