title: Gradle external class required by plugin on runtime
body: <p>I'm creating custom Gradle plugin for internal company use. It will add few tasks to project and behaviour of one task can be customized by plugin users. Idea is to have plugin property that will contain external class name. This class must implement appropriate interface to be correctly used. Plugin's task will instantiate objects for this class and use it during execution.</p>
  
  <p>Reasons for that - there are several reasonably different patterns used by different teams in company. So set of these "external classes" will be created and published. Each team can choose which one to use for their build configuration. Or even can create a new one if there are reasons for that. So I want this thing to be configurable on a build level.</p>
  
  <p>I'm failing to setup this kind of dependency in build.gradle script. Let me show you code on which I'm trying to reproduce and solve issue:</p>
  
  <pre><code>buildscript{
      repositories {
          mavenCentral()
          maven{
              url "http://our-internal-nexus/repository/maven-releases/"
          }
          dependencies{
              classpath 'my.company:myplugin:0.1'
              classpath 'my.other.company:extClass:0.1'
  
          }
      }
  }
  
  apply plugin: 'my.company.myplugin'
  
  MyInput{
      managerClass = "ExtClass"
  }
  </code></pre>
  
  <p>myplugin - artifact of my plugin, and extclass - external class that should be instantiated by plugin's task. </p>
  
  <p>When I try to execute plugins task: <em>gradle hellotask</em> I receive error: java.lang.ClassNotFoundException: ExtClass</p>
  
  <p>I put a code to hellotask class definition to show me the classpath. The only thing it shows is <code>C:/work/Projects/development/gradle-4.0.1/lib/gradle-launcher-4.0.1.jar</code>. So for me it looks like no path to extClass jar provided by gradle to plugin in runtime so it can't find it. </p>
  
  <p>Below you can find source code of plugin and extClass if this may help.</p>
  
  <p><strong>MyPlugin</strong></p>
  
  <p>MyPlugin.java</p>
  
  <pre><code>package my.company;
  import org.gradle.api.*;
  
  //Plugin definition
  public class MyPlugin implements Plugin&lt;Project&gt;{
      @Override
      public void apply(Project project){
          project.getExtensions().create("MyInput", MyPluginExtension.class);
          HelloTask helloTask = project.getTasks().create("helloTask", HelloTask.class);
      }
  
  }
  </code></pre>
  
  <p>HelloTask.java</p>
  
  <pre><code>package my.company;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  import org.gradle.api.*;
  import org.gradle.api.tasks.*;
  
  //Plugin task
  public class HelloTask extends DefaultTask {
      @TaskAction
      public void action() {
  
      //Print classpath
      ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();
  
      URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
  
      for(int i=0; i&lt; urls.length; i++)   {
          System.out.println(urls[i].getFile());
      }
  
      //Try to instantiate class
      try {
          MyPluginExtension extension = getProject().getExtensions().findByType(MyPluginExtension.class);
          Object instance = Class.forName(extension.getManagerClass()).newInstance();
      }
      catch (ClassNotFoundException e) {
              e.printStackTrace();
              throw new GradleException("Class not found");
      } catch (IllegalAccessException e) {
          e.printStackTrace();
          throw new GradleException("IllegalAccessException");
      } catch (InstantiationException e) {
          e.printStackTrace();
          throw new GradleException("InstantiationException");
      }
  
      }
  }
  </code></pre>
  
  <p>MyPluginExtension.java</p>
  
  <pre><code>package my.company;
  
  public class MyPluginExtension {
      private String managerClass = null;
  
      public String getManagerClass(){return this.managerClass;}
      public void setManagerClass(String managerClass){ this.managerClass = managerClass;}
  
  }
  </code></pre>
  
  <p><strong>extClass</strong></p>
  
  <p>extClass.java</p>
  
  <pre><code>package my.other.company;
  
  public class ExtClass {
  
      public void ExtClass(){
          System.out.println("Show me how it works!");
      }
  
  }
  </code></pre>