gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:04:48 25 4
gpt4 key购买 nike

我正在使用 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

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

scalaVersion := "2.10.4-RC1"

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

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

...和重新加载,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

最佳答案

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

结果是 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

要重现,请参阅 build.sbt 中以 print(不是 println)开头的以下 sbt session 和全局配置目录:

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

关于sbt - SBT 0.13 中的任务定义不接受打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20873896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com