Skip to content

Commit 72173d2

Browse files
committed
Fix classpath in QuoteDriver when executing from sbt
1 parent 52bddff commit 72173d2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import dotty.tools.repl.AbstractFileClassLoader
99
import scala.quoted.Expr
1010
import java.io.ByteArrayOutputStream
1111
import java.io.PrintStream
12+
import java.net.URLClassLoader
1213
import java.nio.charset.StandardCharsets
1314

1415
class QuoteDriver extends Driver {
@@ -55,7 +56,15 @@ class QuoteDriver extends Driver {
5556

5657
override def initCtx: Context = {
5758
val ictx = super.initCtx.fresh
58-
val classpath = System.getProperty("java.class.path")
59+
var classpath = System.getProperty("java.class.path")
60+
this.getClass.getClassLoader match {
61+
case cl: URLClassLoader =>
62+
// Loads the classes load by this class loader
63+
// When executing `run` or `test` in sbt the classpath is not in th property java.class.path
64+
val newClasspath = cl.getURLs.map(_.getFile())
65+
classpath = newClasspath.mkString("", ":", if (classpath == "") "" else ":" + classpath)
66+
case _ =>
67+
}
5968
ictx.settings.classpath.update(classpath)(ictx)
6069
ictx
6170
}

0 commit comments

Comments
 (0)