无法添加自定义 SBT 操作

发布于 2024-10-07 01:59:26 字数 1902 浏览 8 评论 0原文

我刚刚开始使用 SBT。 为了添加自定义操作,我执行了以下任务,并将 .scala 文件添加到“project”文件夹中:SBT wiki 指南。

//MyProject.scala
import sbt._

class HelloWorldProject(info: ProjectInfo) extends DefaultProject(info)
{
  lazy val hi = task { println("Hello World"); None }
}

添加 scala src 文件进行配置后,项目文件夹的布局如下所示。

/development/scala/SomeScalaProject/
|~lib/
|~project/
| |~boot/
| | |~scala-2.7.7/
| | | |~lib/
| | | | |-scala-compiler.jar [RO]
| | | | `-scala-library.jar [RO]
| | | `~org.scala-tools.sbt/
| | |   `~sbt/
| | |     `+0.7.4/
| | |~scala-2.8.1/
| | | `~lib/
| | |   |-scala-compiler.jar [RO]
| | |   `-scala-library.jar [RO]
| | `-sbt.boot.lock
| |-build.properties
| |
| `-MyProject.scala  //here
|
|+src/

但即使在“重新加载”或“更新”之后,在 SBT 中运行 hi 任务根本不可用。我缺少什么?

D:\development\scala\SBEStudy>java -Xmx512M -jar "D:\development\.common\sbt-la
nch-0.7.4.jar" update
[info] Building project SomeScalaProject 1.0 against Scala 2.8.1
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
[info]
[info] == update ==
[warn] No dependency configuration found, using defaults.
[info] :: retrieving :: nephilim.practice#scalabyexample_2.8.1 [sync]
[info]  confs: [default]
[info]  0 artifacts copied, 0 already retrieved (0kB/391ms)
[info] == update ==
[success] Successful.
[info]
[info] Total time: 1 s, completed 2010. 12. 8 오후 7:14:39
[info]
[info] Total session time: 2 s, completed 2010. 12. 8 오후 7:14:39
[success] Build completed successfully.
> reload
[info] Building project SomeScalaProject 1.0 against Scala 2.8.1
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
> hi
[error] No action named 'hi' exists.
[info] Execute 'help' for a list of commands or 'actions' for a list of availab
e project actions and methods.

I just got started with SBT.
To add a custom action, I made a following task and add that .scala file to 'project' folder as SBT wiki guides.

//MyProject.scala
import sbt._

class HelloWorldProject(info: ProjectInfo) extends DefaultProject(info)
{
  lazy val hi = task { println("Hello World"); None }
}

after adding the scala src file for configuration, layout of the project folder look like this.

/development/scala/SomeScalaProject/
|~lib/
|~project/
| |~boot/
| | |~scala-2.7.7/
| | | |~lib/
| | | | |-scala-compiler.jar [RO]
| | | | `-scala-library.jar [RO]
| | | `~org.scala-tools.sbt/
| | |   `~sbt/
| | |     `+0.7.4/
| | |~scala-2.8.1/
| | | `~lib/
| | |   |-scala-compiler.jar [RO]
| | |   `-scala-library.jar [RO]
| | `-sbt.boot.lock
| |-build.properties
| |
| `-MyProject.scala  //here
|
|+src/

But even after 'reload' or 'update', running the hi task in SBT is not available at all. what am i missing?

D:\development\scala\SBEStudy>java -Xmx512M -jar "D:\development\.common\sbt-la
nch-0.7.4.jar" update
[info] Building project SomeScalaProject 1.0 against Scala 2.8.1
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
[info]
[info] == update ==
[warn] No dependency configuration found, using defaults.
[info] :: retrieving :: nephilim.practice#scalabyexample_2.8.1 [sync]
[info]  confs: [default]
[info]  0 artifacts copied, 0 already retrieved (0kB/391ms)
[info] == update ==
[success] Successful.
[info]
[info] Total time: 1 s, completed 2010. 12. 8 오후 7:14:39
[info]
[info] Total session time: 2 s, completed 2010. 12. 8 오후 7:14:39
[success] Build completed successfully.
> reload
[info] Building project SomeScalaProject 1.0 against Scala 2.8.1
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
> hi
[error] No action named 'hi' exists.
[info] Execute 'help' for a list of commands or 'actions' for a list of availab
e project actions and methods.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事未完 2024-10-14 01:59:26

这是我的错误。 :(
“MyProject.scala”应位于 /project/build 目录下,而不是 /project 目录下。

It was my mistake. :(
"MyProject.scala" should be located under /project/build directory instead of /project directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文