Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have Eclipse recognize dependencies from SBT

People also ask

How do we specify library dependencies in SBT?

The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.

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.

Where are dependencies downloaded in SBT?

All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.


If you are using sbteclipse plugin it's achievable in a simple way. In sbt type:

reload
eclipse with-source=true

Then in eclipse, hit F5 on a project folder to refresh it. Or right-click and choose "Refresh". Just works.


This is probably not the answer you are looking for and I admit it is not elegant but it currently works for me, meaning that I think it takes less time for me to periodically do the following instead of researching and finding a more elegant solution.

I assume you are using the sbt-eclipse plugin ( https://github.com/typesafehub/sbteclipse ). When I add new dependencies to my project ( which is actually pretty rare ) I simply regenerate my eclipse project files from the plugin. The downside of this is that I have a multiple module project and after I refresh the projects in eclipse I need to re-add the inter-project dependencies in the eclipse build path editor.

Like I mentioned it is pretty hacky but all in all I really don't loose that much time doing it. It's not pretty but it works.

Best of luck, Andy


I use the Apache IvyDE plugin for Eclipse, and I've had more luck with this approach. It's only described in the old sbt docs, but works with sbt 0.11

First, install the IvyDE plugin in Eclipse and restart.

Run the sbt command deliver-local - this will create an XML ivy file of your dependencies.

In Eclipse, under your Project/Properties - Java Build Path - Libraries, click "Add Library" and choose "IvyDE Managed Dependencies" then select the file target/scala-2.9.1/ivy-projectversion.xml

When you add a new dependency to build.sbt, run the sbt commands reload and deliver-local again. Then right-click the Ivy library for your project in the Package Explorer - it will be called "target/scala-2.9.1/ivy-projectversion.xml [compile,test]", and click the second "Refresh" menu item (between "Refresh" and "Reload Settings" - not "F5 Refresh" ).


In command prompt go to the project folder and type

sbt eclipse

This should generate the appropriate .classpath entries in eclipse project.

Go back to eclipse, select the project and press f5, this will reload the referenced libs.


All you need is execute from your project home:

sbt "eclipse with-source=true"

or enter sbt console and write:

eclipse with-source=true

BTW: I don't know if from Jan '12 something has changed but now it seems much more simple.