问题
I'm using Scala 2.11.1 and sbt 0.13.5.
I have an sbt plugin that contains a helper function to create input tasks as follows (the implementation is stripped away as it's irrelevant to the problem):
def register(name: String, description: String): Def.Setting[InputTask[Unit]] = {
InputKey[Unit](name, description) <<= Def.inputTask {
println("test")
}
}
This function compiles and works just fine in Scala 2.10.4, however once I switch to 2.11.1 it fails with the following error:
can't expand macros compiled by previous versions of Scala
Is the Def.inputTask
macro simply broken in Scala 2.11.1, or am I missing some glaring detail?
Right now the above function is residing in the simplest sbt plugin imaginable. There are no dependencies at all, either.
回答1:
sbt 0.13.x series uses Scala 2.10.x when it loads up, so sbt 0.13.x itself must be compiled against Scala 2.10, and so do all sbt plugins for 0.13.x.
Note: sbt 0.13 can define Scala projects using 2.11.x.
回答2:
If you're running scala 2.11.x, use this line in your build.sbt file .
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
回答3:
This is what I have just tried and it works with scalaVersion
of 2.11.6
The code is checked in on github, in case you want to check
I have sbt
version as
$ sbt --version
sbt launcher version 0.13.8
My project settings looks like
object LearningScalaBuild extends Build {
lazy val commonSettings = Seq(
organization := "com.learner",
version := "0.1.0",
scalaVersion := "2.11.6",
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
)
lazy val root = project.in(file(".")).aggregate(s99, ahka)
lazy val s99 = project.in(file("s99"))
.settings(commonSettings: _*)
lazy val ahka = project.in(file("ahka"))
.settings(commonSettings: _*)
.settings(libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.9")
}
I ran it on Travis CI
and it seems to work well
[info] Resolving org.scalatest#scalatest_2.11;2.2.4 ...
[info] Resolving org.scala-lang#scala-reflect;2.11.2 ...
[info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.2 ...
[info] Resolving org.scala-lang#scala-compiler;2.11.6 ...
[info] Resolving org.scala-lang#scala-reflect;2.11.6 ...
[info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.3 ...
[info] Resolving org.scala-lang.modules#scala-parser-combinators_2.11;1.0.3 ...
[info] Resolving jline#jline;2.12.1 ...
[info] downloading https://repo1.maven.org/maven2/com/typesafe/akka/akka-actor_2.11/2.3.9/akka-actor_2.11-2.3.9.jar ...
[info] [SUCCESSFUL ] com.typesafe.akka#akka-actor_2.11;2.3.9!akka-actor_2.11.jar (253ms)
[info] downloading https://repo1.maven.org/maven2/com/typesafe/config/1.2.1/config-1.2.1.jar ...
[info] [SUCCESSFUL ] com.typesafe#config;1.2.1!config.jar(bundle) (170ms)
[info] Done updating.
[info] 'compiler-interface' not yet compiled for Scala 2.11.6. Compiling...
[info] Run completed in 13 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[info] Compilation completed in 18.159 s
[info] Compiling 1 Scala source to /home/travis/build/hhimanshu/learningScala/s99/target/scala-2.11/test-classes...
[info] P01Spec:
[info] [Dummy Test] A List
[info] - must return true when provided empty list
[info] Run completed in 259 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 28 s, completed May 30, 2015 3:41:26 AM
The command "sbt ++2.11.6 test" exited with 0.
Done. Your build exited with 0.
回答4:
I changed the build.sbt file. Now its working for me. Below is the change
scalaVersion := "2.11.6"
scalacOptions += "-deprecation"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
来源:https://stackoverflow.com/questions/24103043/why-doesnt-the-def-inputtask-macro-work-in-scala-2-11-1