简体   繁体   English

为什么Def.inputTask宏在Scala 2.11.1中不起作用?

[英]Why doesn't the Def.inputTask macro work in Scala 2.11.1?

I'm using Scala 2.11.1 and sbt 0.13.5. 我正在使用Scala 2.11.1和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): 我有一个sbt插件,其中包含一个辅助函数来创建输入任务,如下所示(实现被删除,因为它与问题无关):

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: 此函数在Scala 2.10.4中编译并正常工作,但是一旦切换到2.11.1,它就会失败并出现以下错误:

can't expand macros compiled by previous versions of Scala 无法扩展由以前版本的Scala编译的宏

Is the Def.inputTask macro simply broken in Scala 2.11.1, or am I missing some glaring detail? 是否在Scala 2.11.1中简单地破坏了Def.inputTask宏,还是我错过了一些明显的细节?

Right now the above function is residing in the simplest sbt plugin imaginable. 现在,上面的函数驻留在可以想象的最简单的sbt插件中。 There are no dependencies at all, either. 完全没有依赖关系。

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. sbt 0.13.x系列在加载时使用Scala 2.10.x,因此sbt 0.13.x本身必须针对Scala 2.10编译,所有sbt插件都是针对0.13.x编译的。

Note : sbt 0.13 can define Scala projects using 2.11.x. 注意 :sbt 0.13可以使用2.11.x定义Scala项目。

If you're running scala 2.11.x, use this line in your build.sbt file . 如果您正在运行scala 2.11.x,请在build.sbt文件中使用此行。

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test" libraryDependencies + =“org.scalatest”%“scalatest_2.11”%“2.2.4”%“test”

This is what I have just tried and it works with scalaVersion of 2.11.6 这是我刚刚尝试过的,它适用于2.11.6 scalaVersion
The code is checked in on github , in case you want to check 如果你想检查,代码在github上签入

I have sbt version as 我有sbt版本

$ 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 我在Travis CI上运行它似乎运作良好

[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.

I changed the build.sbt file. 我更改了build.sbt文件。 Now its working for me. 现在它为我工作。 Below is the change 以下是变化

scalaVersion := "2.11.6" scalaVersion:=“2.11.6”

scalacOptions += "-deprecation" scalacOptions + =“ - deprecation”

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test" libraryDependencies + =“org.scalatest”%“scalatest_2.11”%“2.2.4”%“test”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM