在SBT 0.13的任务定义中不接受打印?

时间:2014-01-01 22:19:27

标签: sbt

我正在使用SBT 0.13.1

project / build.properties 如下:

sbt.version=0.13.1

执行sbt about打印出以下内容:

$ sbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-0.13.1/project
[info] Set current project to sbt-0-13-1 (in build file:/Users/jacek/sandbox/so/sbt-0.13.1/)
[sbt-0-13-1]> about
[info] This is sbt 0.13.1
[info] The current project is {file:/Users/jacek/sandbox/so/sbt-0.13.1/}sbt-0-13-1 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.4-RC1
[info] Available Plugins: com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, np.Plugin, net.virtualvoid.sbt.graph.Plugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3

执行以下任务 - hello - build.sbt

scalaVersion := "2.10.4-RC1"

lazy val hello = taskKey[Unit]("An example task")

hello := {
  print("Sleeping for a sec...")
  println("done.")
}

...和reload,sbt报告[error] Type error in expression

[sbt-0-13-1]> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-0.13.1/project
/Users/jacek/sandbox/so/sbt-0.13.1/build.sbt:6: error: type mismatch;
 found   : String("Sleeping for a sec...")
 required: sbt.TaskKey[String]
  print("Sleeping for a sec...")
        ^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?

当我将print更改为println时,任务定义正确。

Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? r
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-0.13.1/project
[info] Set current project to sbt-0-13-1 (in build file:/Users/jacek/sandbox/so/sbt-0.13.1/)
[sbt-0-13-1]> hello
Sleeping for a sec...
done.
[success] Total time: 0 s, completed Jan 4, 2014 10:31:43 AM

任务定义中是否不接受print

1 个答案:

答案 0 :(得分:1)

schleichardt的帮助下,我终于可以找出导致print任务中不接受hello的问题。

事实证明,在全局配置目录中使用the sbt-dependency-graph plugin,即~/.sbt/0.13/(或由sbt.global.base指定的目录),sbt无法初始化任务,从而导致错误。

$ cat plugins/sbt-dependency-graph.sbt
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4")

$ cat sbt-dependency-graph.sbt
net.virtualvoid.sbt.graph.Plugin.graphSettings

要重现,请参阅print中的println开头{ build.sbt}以及全局配置中的以下sbt会话目录:

jacek:~/sandbox/so/sbt-0.13.1
$ tree
.
├── build.sbt
└── project
    └── build.properties

1 directory, 2 files

jacek:~/sandbox/so/sbt-0.13.1
$ cat build.sbt
scalaVersion := "2.10.4-RC1"

lazy val hello = taskKey[Unit]("An example task")

hello := {
  print("Sleeping for a sec...")
  println("done.")
}

jacek:~/sandbox/so/sbt-0.13.1
$ sbt -Dsbt.global.base=/tmp/so
Getting org.scala-sbt sbt 0.13.1 ...
:: retrieving :: org.scala-sbt#boot-app
    confs: [default]
    43 artifacts copied, 0 already retrieved (12646kB/154ms)
Getting Scala 2.10.3 (for sbt)...
:: retrieving :: org.scala-sbt#boot-scala
    confs: [default]
    5 artifacts copied, 0 already retrieved (24447kB/204ms)
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-0.13.1/project
[info] Updating {file:/Users/jacek/sandbox/so/sbt-0.13.1/project/}sbt-0-13-1-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to sbt-0-13-1 (in build file:/Users/jacek/sandbox/so/sbt-0.13.1/)
> hello
Sleeping for a sec...done.
[success] Total time: 0 s, completed Jan 4, 2014 1:35:22 PM

到目前为止。

在全局配置目录中为the sbt-dependency-graph plugin创建文件。

jacek:/tmp/so
$ cat plugins/sbt-dependency-graph.sbt
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4")

jacek:/tmp/so
$ cat sbt-dependency-graph.sbt
net.virtualvoid.sbt.graph.Plugin.graphSettings

...和reload

> reload
[info] Loading global plugins from /private/tmp/so/plugins
[info] Updating {file:/tmp/so/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-0.13.1/project
[info] Updating {file:/Users/jacek/sandbox/so/sbt-0.13.1/project/}sbt-0-13-1-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
/Users/jacek/sandbox/so/sbt-0.13.1/build.sbt:6: error: type mismatch;
 found   : String("Sleeping for a sec...")
 required: sbt.TaskKey[String]
  print("Sleeping for a sec...")
        ^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?

print更改为println(r)etry时,它再次正常运行。

Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? r
[info] Loading global plugins from /private/tmp/so/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-0.13.1/project
[info] Set current project to sbt-0-13-1 (in build file:/Users/jacek/sandbox/so/sbt-0.13.1/)
> hello
Sleeping for a sec...
done.
[success] Total time: 0 s, completed Jan 4, 2014 1:43:59 PM