title: Custom Java Based Gradle Plugin and Classpath of Consuming Projects
body: <p>I have made a plugin with a task that will search the classpath for classes annotated with a specific annotation, using the Reflections library from google (<a href="https://code.google.com/p/reflections/" rel="nofollow" title="here">here</a>). However, when consuming the plugin and running the task, the current modules' classpath is not used. How can I get the task to look at the output from the jar task (from the java plugin) as on the classpath?</p>
  
  <p>Here is my example plugin:</p>
  
  <pre><code>package com.myplugin;
  
  import org.gradle.api.Plugin;
  import org.gradle.api.Project;
  
  public class MyPlugin implements Plugin&lt;Project&gt; {
      @Override
      public void apply(Project project) {
          project.getTasks().create("myplugintask", MyPluginTask.class);
      }
  }
  </code></pre>
  
  <p>My Task Code:</p>
  
  <pre><code>package com.myplugin;
  
  import lombok.Data;
  import org.gradle.api.DefaultTask;
  import org.gradle.api.tasks.TaskAction;
  import org.reflections.Reflections;
  
  public class MyPluginTask extends DefaultTask {
      @TaskAction
      public void reflect() {
          Reflections reflections = new Reflections("com.consumer.reflected");
  
          for (Class&lt;?&gt; clazz : reflections.getTypesAnnotatedWith(Data.class)) {
              getLogger().info(clazz.toString());
          }
      }
  }
  </code></pre>
  
  <p>And my consuming project has a class:</p>
  
  <pre><code>package com.consumer.reflected;
  
  import lombok.Data;
  
  @Data
  public class SomeClass {
  }
  </code></pre>
  
  <p>I would expect to be able to run:</p>
  
  <pre><code>gradle myplugintask
  </code></pre>
  
  <p>And see the SomeClass, but reflections returns zero results.</p>
  
  <p>Note: I have tried implementating an instantiation of the plugin (and task) inside of the consumer project, and ran it as a standard jar, and that succeeds (output shows SomeClass)</p>