25

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.

Michael Zajac
  • 53,182
  • 7
  • 105
  • 130

4 Answers4

31

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.

Eugene Yokota
  • 90,473
  • 43
  • 204
  • 301
  • 3
    In your build.sbt file, make sure you `scalaVersion := "2.10.4"` instead of something like `scalaVersion := "2.11.x"` – Shafique Jamal Nov 16 '14 at 16:58
  • Why will intellij let me create a project with SBT 0.13.8 and scala 2.11.6 ? – Florian F Apr 25 '15 at 14:15
  • 1
    @FlorianF It is specifically sbt *plugins* that must use 2.10, not all projects. – Michael Zajac Apr 29 '15 at 13:05
  • I might need the t's crossed to see the causal connection. Is it the case that sbt itself doesn't compile using 2.11, and therefore trying to use its symbols in a 2.11 project falls back to trying 2.10 sbt macro code, which fails with the error? – matanster Oct 20 '15 at 18:33
16

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"

Rodrigo Dias
  • 1,242
  • 2
  • 13
  • 17
  • 3
    Why did someone upvote this? This *nothing* to do with the question, at all. This is completely irrelevant. – Michael Zajac May 22 '15 at 14:51
  • 3
    Rodrigo is addressing a similar error message that is caused when using Scala 2.11.x with scalatest_2.10. Funny, googling the error message brought me to this question, but it was Rodrigo's answer that fixed my issue. Thanks Rodrigo! (Might want to edit your answer to explain that your answer is there for noobs googling this error message). – Alfred Fazio Jun 03 '15 at 15:02
  • And yet it is still irrelevant to this question. – Michael Zajac Jun 04 '15 at 02:18
  • @m-z searching for the Scala test library on maven shows scalatest_2.10 on the first page. maybe everyone added that one then wondered why they were getting the problem. – coderatchet Jan 14 '16 at 05:44
  • @AlfredFazio is right. Also, Rodrigo has a fix to an unrelated to this question, yet super helpful. – Abhishek Mehta Nov 04 '16 at 23:59
-1

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.
daydreamer
  • 73,989
  • 165
  • 410
  • 667
-2

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"