Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency injection in a maven plugin

I am developing a maven plugin and to make it more testable I would like to use a light-weight dependency injection framework(like Guice) to manage services etc but while I can get them to integrate with applications I haven't been able to get them integrated with my plugin. Is there any way to do this save for doing the dependency-injection in a static fashion?

like image 665
user439407 Avatar asked Nov 02 '22 04:11

user439407


1 Answers

Maven already provides you with embedded IoC container called Plexus. You can include 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 properties

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

You can find more information on maven plugin dev site and plexus documentation.

like image 120
hoaz Avatar answered Nov 09 '22 06:11

hoaz