Closed lihaoyi closed 6 years ago
@Mogztter any idea what this is?
object scala in compiler mirror not found.
might be indicative of a classpath issue. @lihaoyi If you have a test repo reproducing that issue, I'd be interested in checking if it's not a coursier issue…
@alexarchambault the code block above shows the contents of all files and the command necessary to reproduce
@lihaoyi Are you using Java8 ? Java9 ? I will try to reproduce this issue.
EDIT: I can reproduce this issue with JDK8
java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
I think the Scala library is missing from the classloader used to load the class TwirlCompiler
.
https://github.com/playframework/twirl/blob/1d7c603352510809908d155393651748cc601e5e/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala#L507
At this line, we can see that the TwirlCompiler
is using scala.tools.nsc.interactive.Global
.
I tried to add the following dependency in the twirlClasspath
function but without success:
ivy"org.scala-lang:scala-compiler:2.12.4"
I've built a local version of mill
using the procedure described in the README and I've noticed that the dependency is mill-contrib-twirllib
instead of mill-twirllib
:
import $ivy.`com.lihaoyi::mill-contrib-twirllib:0.2.6-16-6220c7-DIRTY85e9bfb4`
Anyway it's not working. Some people on Stackoverflow mention the settings settings.usejavacp.value = true
but I'm a bit skeptical...
I've noticed that the TwirlCompiler
class is using the following code to locate classes/sources code:
Class.forName("scala.Predef").getProtectionDomain.getCodeSource
When running the test suite the return value is something like file:/path/to/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.6/scala-library-2.12.6.jar <no signer certificates>
.
But when running the mill
command the return value is file:/path/to/mill-release <no signer certificates>
.
It may explain why the presentation compiler instantiated in the TwirlCompiler
can't find the Scala library.
I don't really know why the TwirlCompiler
is using this strategy and how we can resolve this issue... Any idea @lihaoyi @rockjam ?
For reference:
If that's of any help, as a workaround, running mill via coursier fixes that
$ coursier launch com.lihaoyi:mill-dev_2.12:0.2.4 -M mill.MillMain -- \
show foo.compileTwirl
Compiling (synthetic)/ammonite/predef/interpBridge.sc
Compiling (synthetic)/ammonite/predef/DefaultPredef.sc
Compiling …/build.sc
[1/1] show
[4/4] foo.compileTwirl
{
"analysisFile": "…/out/foo/compileTwirl/dest/zinc",
"classes": "ref:586a1b4f:…/out/foo/compileTwirl/dest/html"
}
(because coursier launch
relies on standard jars, like in the tests, rather than a fat jar)