如何使用sbt-eclipse创建项目的Eclipse项目文件?

Cla*_*ied 17 eclipse macos scala sbt

我按照官方文档在我的sbt项目中设置了插件:

  1. 添加addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")~/.sbt/plugins/plugins.sbt文件
  2. cd编辑并运行 sbt
  3. 在sbt shell中,键入 eclipse

这就是我遇到以下错误的地方:

> eclipse
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse (similar: sbteclipse)
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error]        ^
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

在此先感谢您提供给我的任何帮助.

$ /opt/sbt-0.13.5/bin/sbt
[warn] The global sbt directory is now versioned and is located at /Users/first.last/.sbt/0.13.
[warn]   You are seeing this warning because there is global configuration in /Users/first.last/.sbt but not in /Users/first.last/.sbt/0.13.
[warn]   The global sbt directory may be changed via the sbt.global.base system property.
[info] Loading project definition from /Users/first.last/git/myproject/project
[info] Set current project to myproject (in build file:/Users/first.last/git/myproject/)
> eclipse
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error]        ^
Run Code Online (Sandbox Code Playgroud)

Jac*_*ski 23

我正在使用sbt 0.13.5.

$ sbt --version
sbt launcher version 0.13.5
Run Code Online (Sandbox Code Playgroud)

在执行的目录sbt about中检查build/sbt设置.

$ sbt about
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to sbteclipse (in build file:/Users/jacek/sandbox/sbteclipse/)
[info] This is sbt 0.13.5
[info] The current project is {file:/Users/jacek/sandbox/sbteclipse/}sbteclipse 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.4
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, net.virtualvoid.sbt.graph.Plugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
Run Code Online (Sandbox Code Playgroud)

目录中没有文件(忽略target它,因为它在启动时由sbt自动创建,可以随时删除).

$ tree
.
`-- target

1 directory, 0 files
Run Code Online (Sandbox Code Playgroud)

然后我运行sbt shell sbt以确保没有eclipse命令存在.

$ sbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to sbteclipse (in build file:/Users/jacek/sandbox/sbteclipse/)
> eclipse
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse (similar: sbteclipse)
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error]        ^
Run Code Online (Sandbox Code Playgroud)

我可以重现你的问题.移动到设置插件-我并没有关闭SBT外壳.

继文档紧密我打开~/.sbt/0.13/plugins/plugins.sbt有它,如下所示:

$ cat ~/.sbt/0.13/plugins/plugins.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
Run Code Online (Sandbox Code Playgroud)

使用文件中的插件,我reload在sbt shell中触发了加载更改.

> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to sbteclipse (in build file:/Users/jacek/sandbox/sbteclipse/)
> eclipse
[info] About to create Eclipse project files for your project(s).
[info] Updating {file:/Users/jacek/sandbox/sbteclipse/}sbteclipse...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Successfully created Eclipse project files for project(s):
[info] sbteclipse
Run Code Online (Sandbox Code Playgroud)

如您所见,插件已正确加载并生成文件.按照步骤操作,您应该安装插件,没有任何问题.


zin*_*ing 5

对于sbt 0.13及以上

将sbteclipse添加到插件定义文件中.你可以使用:

  1. 〜/ .sbt/0.13/plugins/plugins.sbt的全局文件(适用于版本0.13及更高版本)

  2. PROJECT_DIR/project/plugins.sbt中的项目特定文件

    addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
    
    Run Code Online (Sandbox Code Playgroud)