I have some configuration problem I can't see. I've followed the instructions provided in the latest twirl README, but the html package is undefined according to the compiler.
I've included the
sbt-twirlplugin in theproject/plugins.sbtfileaddSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.3")In the
project/Build.scalaI've enabled the pluginlazy val root = Project(id = "proj", base = file(".")) .enablePlugins(play.twirl.sbt.SbtTwirl) .settings(rootSettings: _*)I've placed the
page.scala.htmlin thesrc/main/twirlsubdirectory (either directly or using thecom/somethin/coolpath)
Now if I'm trying to import the html package (or com.somethin.cool.html) the compiler complains it's undefined. I can compile the templates with 'twirlCompile' command, and they get properly generated in the target subdirectory, but they are invisible to the main project.
Note: This is not a PlayFramework project
- Scala: 2.10.4
- sbt: 0.13.6
- twirl: 1.0.3
I similarly use Twirl in a non-Play project.
If you placed the file in
src/main/com/somethin/coolthen you should expect the generated class to be found atcom.somethin.cool.html.pageIf you placed the file in
src/main/twirl/then you should expect the generated class to be found attwirl.html.pageThe Twirl compiler looks at the files it finds and puts the "html" (extension really, it could be "txt" or "json" or ...) directory underneath the longest common sub-path of the files. So, say you had:
Then the common longest sub-path of the files is src/main (i.e. the root of the classpath). You're then going to get these classes at:
Now, to address the "compiler complains it's undefined" part: you could mean several things by this.
If you mean the actual Scala Compiler being run by sbt doesn't find it, I've never had a problem with that. The generated source and .class files are in the path under
target/scala_2.10/twirl/main. In that case, you might want to be more clear about the compiler's complaint and your compilation classpath.But, if you mean that your IDE doesn't recognize the source file, you'll need to add the directory
target/scala_2.10/twirl/mainas one of the source directories used by your project.One other issue I have with Twirl usage is that the IntelliJ IDEA 14 IDE doesn't really support the twirl compiler, at least not outside a Play project. Whenever I update a Twirl template, I invariably have to compile it with sbt instead of IntelliJ IDEA's built-in compiler. The JetBrains people tell me they are working on a fix for this (I've logged an issue with them about it.)
UPDATE(12/14/14): The JetBrains issue I logged is at this location. The test case for it is here on github