title: SBT how to use classes from Build.sbt inside plugin Task execution
body: <p>Any classes defined in <code>project/*.scala</code> files are made available for use by SBT inside the build definition code.</p>
  
  <p>I would like those classes to be available during the execution of an SBT plugin task, but they do not appear to be available.</p>
  
  <p>Why is that, and how can I fix it?</p>
  
  <p>The specific problem I am trying to solve is adding custom rules for <code>Scalastyle</code>. The project <a href="https://github.com/scalastyle/scalastyle/issues/25" rel="noreferrer">does not currently support writing your own rules</a>, but I thought I might be able to add a rule to the <code>project/*.sbt</code> files and then use it inside <code>Scalastyle</code>.</p>
  
  <p>If I define a rule in <code>project/MyRule.scala</code>, then it is available in the <code>project/Build.scala</code> settings:</p>
  
  <pre><code>object MyBuild extends Build {
  
    lazy val project = Project("MyProject", file("."))
      .settings(ScalastylePlugin.Settings: _*)
  
    // my rule is available in this classloader:
    val test = classOf[MyRule].getName
  
    ...
  }
  </code></pre>
  
  <p>... but when the ScalastylePlugin Task runs, the classloader it is using cannot see that class:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: MyRule
  java.net.URLClassLoader$1.run(URLClassLoader.java:202)
  java.security.AccessController.doPrivileged(Native Method)
  java.net.URLClassLoader.findClass(URLClassLoader.java:190)
  java.lang.ClassLoader.loadClass(ClassLoader.java:307)
  java.lang.ClassLoader.loadClass(ClassLoader.java:248)
  java.lang.Class.forName0(Native Method)
  java.lang.Class.forName(Class.java:169)
  org.scalastyle.Checker$.newInstance(Checker.scala:194)
  org.scalastyle.Checker$$anonfun$verifySource0$1.apply(Checker.scala:116)
  org.scalastyle.Checker$$anonfun$verifySource0$1.apply(Checker.scala:116)
  ...
  org.scalastyle.ScalastyleChecker.checkFiles(Checker.scala:64)
  org.scalastyle.sbt.Tasks$.runScalastyle(Plugin.scala:121)
  org.scalastyle.sbt.Tasks$.doScalastyle(Plugin.scala:90)
  org.scalastyle.sbt.ScalastylePlugin$$anonfun$4$$anonfun$apply$1.apply(Plugin.scala:63)
  org.scalastyle.sbt.ScalastylePlugin$$anonfun$4$$anonfun$apply$1.apply(Plugin.scala:63)
  scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
  scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
  scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
  sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
  sbt.std.Transform$$anon$4.work(System.scala:64)
  sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
  sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
  sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
  sbt.Execute.work(Execute.scala:244)
  sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
  sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
  sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
  sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
  java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
  ...
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>I have inspected the classloader in use during the <code>Scalastyle</code> task, and it has all the SBT librarydependency jars on its classpath, but no classes from the SBT project.</p>
  
  <p>How can I add these classes to its classpath?</p>