Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sbt-eclipse to create Eclipse project files of a project?

I followed the official documentation to set up the plugin in my sbt project:

  1. Added addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0") to ~/.sbt/plugins/plugins.sbt file
  2. cded to a project and ran sbt
  3. 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]        ^

What am I missing?

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]        ^
like image 599
Classified Avatar asked Jul 10 '14 23:07

Classified


People also ask

How do I import a Scala project into Eclipse?

To import the Scala IDE in your workspace simply click on File > Import. The Eclipse Import dialog will open. There, select General > Existing Projects into Workspace and click Next. A new dialog will open.

Does Eclipse support sbt?

In a console, cd to the top-level folder of your existing sbt project, and enter sbt eclipse to generate the Eclipse project files for all projects in your build. Start Eclipse and switch to the Workspace you want to use for your Lagom project. From the File menu, select Import.


2 Answers

I'm using sbt 0.13.5.

$ sbt --version
sbt launcher version 0.13.5

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

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

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]        ^

I could reproduce your issue. Moving on to setting up the plugin - I did not close the sbt shell.

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")

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.

like image 89
Jacek Laskowski Avatar answered Nov 15 '22 20:11

Jacek Laskowski


For sbt 0.13 and up

Add sbteclipse to your plugin definition file. You can use either:

  1. the global file (for version 0.13 and up) at ~/.sbt/0.13/plugins/plugins.sbt

  2. the project-specific file at PROJECT_DIR/project/plugins.sbt

    addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
    
like image 25
zinking Avatar answered Nov 15 '22 18:11

zinking