Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

Skip to end of metadata
Go to start of metadata

Dependency Injection

Dependency Injection or Inversion of Control (IoC) is done with google guice (https://github.com/google/guice)


public interace MySvc {
    public void myServiceMethod()


public class MySvcImpl implements MySvc {
   public void myServiceMethod() {
       System.out.println("It works!");


public class MyGuiceModule extends com.google.inject.AbstractModule {
    public void configure() {


import com.google.inject.Guice;
import com.google.inject.Inject; 

public class MyPublisher extends Publisher {

    private transient MySvc mySvc;

    private String someJobConfig

    public MyPublisher(String someJobConfig) {
        // no constructor injection
        this.someJobConfig = someJobConfig;

    public void setMySvc(MySvc mySvc) {
        this.mySvc = mySvc;

    public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
	if (mySvc == null)
        	Guice.createInjector(new MyModule()).injectMembers(this);
        // ...
        mySvc.myServiceMethod(); // "it works!"

  • No labels