Gradle current task classpath

I need to load an ejb container from a task to perform some work. This is the code I have

class TalkTask extends DefaultTask {
  def greet(){
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
    properties.put("openejb.validation.output.level", "VERBOSE");
    properties.put("jdbc/dataSource", "new://Resource?type=DataSource");
      Context ctx;
      ctx = new InitialContext(properties);
      Talk talk = (Talk) ctx.lookup("TalkImplLocal");
    }catch (NamingException e) {
    public interface Talk{
  public void hello();
public class TalkImpl implements Talk {
  public void hello(){
    System.out.println("This is hello from the implmentation");
  task sayHello(type: TalkTask)

The problem is Talk and TalkImpl must be in the classpath for the container to load them.

How can I add these classes and the current project dynamically to the task classpath ??

I’d consider launching the EJB container in a separate JVM.

I am looking into gradle API for forking.

I still need the classpath of the current task/plugin to construct a new JVM.

Is there a way to achieve this ??

I’m not aware of an easy solution. Perhaps you could check the ‘buildscript’ block of the current project and its declared dependencies, but you’d also have to check the ‘buildscript’ dependencies of parent projects.