How to have Eclipse recognize dependencies from SBT
Asked Answered
N

6

55

I am trying to figure out how to make Eclipse recognize dependencies that are retrieved using SBT? SBT download the correct dependencies and puts them in my ~/.ivy directory but eclipse doesn't see them. Is there a way to do this?

thanks

Nitid answered 30/1, 2012 at 20:29 Comment(1)
do you still accept the old answer over the newer ones?Depalma
B
32

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

Blancablanch answered 30/1, 2012 at 20:47 Comment(4)
Yeah - this is what I do too. It's not as pretty as it might be, but it does work.Warrick
sbteclipse also correctly adds project dependencies if they are also set up in the sbt build file(s).Glutenous
Any, Please let me know how sbteclipse fails for you at creating the inter-project dependencies. It should definitely work in the latest release (1.5) and the latest milestones (2.0.0-M1..M3) and snapshots (2.0.0-SNAPSHOTS). I suggest you use the sbt mailing list and use the prefix [sbteclipse] in the subject line. Thanks. HeikoHaerr
@HeikoSeeberger: Since the sbt mailing list is being phased out,could you please show us how to solve the OP's problem without hacking?Ares
I
88

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.

Indefatigable answered 7/12, 2012 at 7:3 Comment(3)
This should be the most upvoted answer instead of the one that is right now. Works like a charm!Safford
+1 for with-source that permits to navigate the code of the dependencies I'm using from within Eclipse.Inappreciable
It works fine, when "Referenced Dependencies" is already shown in Eclipse - it adds the new ones. But if the project directly does not show "Referenced Dependencies" (yes, it's happening to me) this does not help.Nutriment
B
32

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

Blancablanch answered 30/1, 2012 at 20:47 Comment(4)
Yeah - this is what I do too. It's not as pretty as it might be, but it does work.Warrick
sbteclipse also correctly adds project dependencies if they are also set up in the sbt build file(s).Glutenous
Any, Please let me know how sbteclipse fails for you at creating the inter-project dependencies. It should definitely work in the latest release (1.5) and the latest milestones (2.0.0-M1..M3) and snapshots (2.0.0-SNAPSHOTS). I suggest you use the sbt mailing list and use the prefix [sbteclipse] in the subject line. Thanks. HeikoHaerr
@HeikoSeeberger: Since the sbt mailing list is being phased out,could you please show us how to solve the OP's problem without hacking?Ares
S
14

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

Subadar answered 1/2, 2012 at 19:54 Comment(2)
yes, this one is "the" solution here. What the OP wants is a native eclipse integration with SBT and this is the closest to it. With this one, eclipse actually sees the IVY dependencies and uses them natively.Depalma
this really solves my biggest pain point with eclipse/sbt and the eclipse scala IDE overall!Depalma
H
7

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.

Hydrogenize answered 13/1, 2014 at 9:19 Comment(0)
F
1

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.

Friederike answered 12/3, 2017 at 23:27 Comment(0)
T
0

The following works for me:

1) close project in Eclipse

2) in my file explorer, browse to my Eclipse project, make sure hidden files are visible

3) open .classpath in a simple text editor

4) copy the bottom entry. For example, in my current project, it is <classpathentry path="/home/natalie/.ivy2/cache/org.scalatest/scalatest_2.9.1/jars/scalatest_2.9.1-1.8.jar" kind="lib"></classpathentry>

5) navigate to my .ivy folder, cache, then down to the library I have added via sbt

6) right click on jar file, select properties, copy the path and jar file name and replace it in the entry I copied in step 4

7) save .classpath

8) open my project on Eclipse

New dependency is now available in Eclipse.

Trivalent answered 9/5, 2013 at 17:15 Comment(1)
the quesstion is how could someone do this automatically and not manually.Mythologize

© 2022 - 2024 — McMap. All rights reserved.