如何使用 sbt-eclipse 创建项目的 Eclipse 项目文件?
我按照官方文档在我的sbt项目中设置插件:
I followed the official documentation to set up the plugin in my sbt project:
- 添加
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" %"2.5.0")
到~/.sbt/plugins/plugins.sbt
文件 cd
ed 到一个项目并运行sbt
- 在 sbt shell 中,输入
eclipse
- Added
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
to~/.sbt/plugins/plugins.sbt
file cd
ed to a project and ransbt
- In sbt shell, typed
eclipse
这就是我遇到以下错误的地方:
That's where I faced the following error:
> 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] ^
我错过了什么?
提前感谢您能给我的任何帮助.
Thanks in advance for any help you can give me.
$ /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] ^
推荐答案
我使用的是 sbt 0.13.5.
I'm using sbt 0.13.5.
$ sbt --version
sbt launcher version 0.13.5
在 empty 目录中执行 sbt about
以检查 build/sbt 设置.
In an empty directory executed sbt about
to check the build/sbt setup.
$ 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
目录中没有文件(忽略 target
,因为它是 sbt 在启动时自动创建的,可以随时删除).
No files are in the directory (disregard target
since it's automatically created by sbt upon startup and can be removed at any time).
$ tree
.
`-- target
1 directory, 0 files
然后我用 sbt
运行 sbt shell 以确保不存在 eclipse
命令.
I then ran the sbt shell with sbt
to ensure no eclipse
command existed.
$ 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] ^
我可以重现您的问题.继续设置插件 - 我确实没有关闭 sbt shell.
I could reproduce your issue. Moving on to setting up the plugin - I did not close the sbt shell.
按照文档 我打开 ~/.sbt/0.13/plugins/plugins.sbt
得到它如下:
Following the documentation closely I opened ~/.sbt/0.13/plugins/plugins.sbt
to have it as follows:
$ cat ~/.sbt/0.13/plugins/plugins.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
使用文件中的插件,我在 sbt shell 中触发了 reload
以加载更改.
With the plugin in the file, I fired reload
in the sbt shell to load the changes.
> 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
如您所见,插件已正确加载并生成文件.按照步骤操作,您应该可以顺利安装插件.
As you can see the plugin was properly loaded and generated the files. Follow the steps and you should have the plugin installed with no issues.
相关文章