Any classes defined in project/*.scala files are made available for use by SBT inside assembly definition code.
I would like these classes to be available during the execution of the SBT plugin task, but they do not seem to be available.
Why is this and how can I fix it?
The specific problem I'm trying to solve is to add custom rules for Scalastyle . The project does not currently support creating its own rules , but I thought I could add the rule to the project/*.sbt and then use it inside Scalastyle .
If I define a rule in project/MyRule.scala , then it is available in the project/Build.scala :
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 ... }
... but when the ScalastylePlugin task is running, the used class loader cannot see this class:
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)
I checked the classloader, which is used during the Scalastyle task, and has all the SBD librarydependency banks in its class path, but does not have classes from the SBT project.
How can I add these classes to my classpath?
scala classloader sbt
Rich
source share