28

I'm using Scala IDE 2.0.1 and SBT 0.11.2 to start with Akka 2.0.1. My build.sbt looks like this:

name := "akka"

version := "0.1"

scalaVersion := "2.9.2"

resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"

libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.1"

As you can see, there's nothing spectacular.

Now how can I tell Eclipse to use the artifact with the sources classifier for the akka-actor library?

In SBT, I can use update-classifiers to download sources and Javadocs to the Ivy repository, but even if I do this before running the eclipse command from the sbteclipse plugin then Eclipse still does not know the sources. Of course, I could do this manually, but this doesn't scale well for more libraries.

I have also tried to use the IvyDE plugin with the deliver-local command. While this integrates the dependency management, it doesn't seem to help with the sources.

Any clues?

Edit: This is the ivy.xml generated from deliver-local:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="default" module="akka_2.9.2" revision="0.1" status="release" publication="20120506225613">
    <description>
    akka
    </description>
</info>
<configurations>
    <conf name="compile" visibility="public" description=""/>
    <conf name="runtime" visibility="public" description="" extends="compile"/>
    <conf name="test" visibility="public" description="" extends="runtime"/>
    <conf name="provided" visibility="public" description=""/>
    <conf name="optional" visibility="public" description=""/>
    <conf name="sources" visibility="public" description=""/>
    <conf name="docs" visibility="public" description=""/>
    <conf name="pom" visibility="public" description=""/>
</configurations>
<publications>
    <artifact name="akka_2.9.2" type="pom" ext="pom" conf="pom"/>
    <artifact name="akka_2.9.2" type="jar" ext="jar" conf="compile"/>
    <artifact name="akka_2.9.2" type="src" ext="jar" conf="sources" e:classifier="sources"/>
    <artifact name="akka_2.9.2" type="doc" ext="jar" conf="docs" e:classifier="javadoc"/>
</publications>
<dependencies>
    <dependency org="org.scala-lang" name="scala-library" rev="2.9.2" conf="compile->default(compile)"/>
    <dependency org="com.typesafe.akka" name="akka-actor" rev="2.0.1" conf="compile->default(compile)"/>
    <exclude org="org.scala-lang" module="scala-library" artifact="*" type="jar" ext="*" matcher="exact"/>
    <exclude org="org.scala-lang" module="scala-compiler" artifact="*" type="jar" ext="*" matcher="exact"/>
    <override org="org.scala-lang" module="scala-library" matcher="exact" rev="2.9.2"/>
    <override org="org.scala-lang" module="scala-compiler" matcher="exact" rev="2.9.2"/>
</dependencies>
</ivy-module>

I'm new to Ivy, so this doesn't tell me much. I just figure that it mentions sources and javadocs, but somehow the IvyDE doesn't pick it up.

Christian Schlichtherle
  • 3,125
  • 1
  • 23
  • 47
  • could you attach screenshots of your ivyde settings? – oers May 07 '12 at 06:19
  • I just went with the default settings after installing the plugin. I also tried to tick "Auto map jar artifacts with unique source artifact" and "Auto map jar artifacts with unique javadoc artifact" with no success - even after closing and reopening the project. – Christian Schlichtherle May 07 '12 at 10:27
  • and the ivde classpath container for the project has all significant configurations checked? – oers May 07 '12 at 10:50
  • [In your project settings click on the IvyDE ClassPath Container and "Edit"](http://stackoverflow.com/questions/9979520/how-ivyde-can-coexist-with-command-line-ant-and-ivy/9988175#9988175). From your ivy.xml you should have compile, sources checked (at least). – oers May 08 '12 at 11:10
  • Thanks, but that didn't help, too. I've given up on this and turned to the NetBeans/Maven/Scala toolchain. – Christian Schlichtherle May 08 '12 at 22:09
  • In the ivy.xml generated by deliver-local, I needed to change the line to be . That gets me sources. – James Moore Oct 31 '12 at 04:51

5 Answers5

35

You can put

EclipseKeys.withSource := true

to your build.sbt, which lets sbteclipse download all sources and makes them accessible within Eclipse. Note, this will download all sources from all configured dependencies. I have no idea how to tell sbt to download only the sources for single dependencies.

kiritsuku
  • 52,967
  • 18
  • 114
  • 136
  • 5
    Since it took me some research and trial-and-error to get this working, here is what needs to be done: In `Build.sbt`, add the import `import com.typesafe.sbteclipse.plugin.EclipsePlugin._`. Into the call to `play.Project.setting(...)`, add `EclipseKeys.withSource := true`. Execute `play update` followed by `play eclipse`. Change to Eclipse, select the project and hit F5. – notan3xit Jul 31 '13 at 10:55
  • 1
    @notan3xit: I think you mean `Build.scala` and not `Build.sbt` since for the `.sbt` files you don't need these imports... – kiritsuku Jul 31 '13 at 13:17
  • Anyone know why this doesn't attach the scaladoc to scala-library.jar in the SCALA_CONTAINER? The source .jar is there, but not the scaladoc/javadoc. – metasim Feb 09 '14 at 03:10
  • 4
    Using the `eclipse with-source=true` command should work as well. If certain dependencies are not downloaded, that might be because you once requested them without the proper resolver. Removing the `exclude_classifiers` cache files for this from the `~/.ivy/` directory helped me here. – EECOLOR Jun 20 '14 at 20:10
  • Pretty straightforward to get working with this plugin: https://github.com/typesafehub/sbteclipse. Install the plugin, then add `EclipseKeys.withSource := true` to build.sbt – sebastian Aug 03 '15 at 23:33
9

Finally I found a solution to let sbt download the sources and tell Eclipse where to find them.

Add in build.sbt:

EclipseKeys.withSource := true

Then run:

rm -rf  ~/.ivy2/cache/

sbt update-classifiers

sbt eclipse

The weird part is that if you already downloaded the dependencies in ivy, you have them in cache and you won't be able to download the sources for them.

sscarduzio
  • 5,938
  • 5
  • 42
  • 54
3

I managed to get this working finally.

I had to use an external ivy settings file:

<ivysettings>
  <properties environment="env" />
  <settings defaultResolver="play" defaultResolveMode="dynamic" />
  <caches defaultCacheDir="${env.PLAY_HOME}/repository/cache" />
  <resolvers>
    <chain name="play">
      <ibiblio name="typesafe-releases" m2compatible="true" root="http://repo.typesafe.com/typesafe/releases" />
      <ibiblio name="sonatype-oss-releases" m2compatible="true" root="http://oss.sonatype.org/content/repositories/releases" />
      <filesystem name="local-filesystem">
        <ivy pattern="${env.PLAY_HOME}/repository/local/[organization]/[module]/[revision]/ivys/ivy.xml" />
        <artifact pattern="${env.PLAY_HOME}/repository/local/[organization]/[module]/[revision]/[type]s/[module](-[classifier]).[ext]" />
      </filesystem>
      <ibiblio name="central-uk" m2compatible="true" root="http://uk.maven.org/maven2" />
      <ibiblio name="typesafe-snapshots" m2compatible="true" root="http://repo.typesafe.com/typesafe/snapshots" />
      <ibiblio name="sonatype-oss-snapshots" m2compatible="true" root="http://oss.sonatype.org/content/repositories/snapshots" />
    </chain>
  </resolvers>
</ivysettings>

And add:

externalIvySettings(baseDirectory(_ / "ivysettings.xml"))

to my Build.scala.

The order of the resolvers in the chain proved to be important, because if Ivy finds a jar but no sources it won't check the other resolvers for sources/javadoc. The repository in the local Play install doesn't have sources or javadoc in.

This gets me source attachments for most of the jars in my dependencies when IvyDE resolves in Eclipse.

Brian Smith
  • 3,383
  • 30
  • 41
2

I find that it's easier to give IvyDE and sbt different ivy cache directories. Yes, it takes more space, but sbt by default doesn't download sources. And once sbt has loaded the cache without sources, IvyDE won't add them. You can tell sbt to fetch them, but for me it's easier just to use more disk space and use two different caches.

I do this by leaving sbt at the default, and setting IvyDE to use this file in Preferences > Ivy > Settings tab > Ivy settings file:

<ivysettings>

    <settings defaultResolver="nexus" />

    <property
        name="nexus-public"
        value="http://localhost:8081/nexus/content/groups/public" />

    <resolvers>

        <ibiblio
            name="nexus"
            m2compatible="true"
            root="${nexus-public}" />
    </resolvers>

    <caches defaultCacheDir="${user.home}/.ivy2eclipse" />

</ivysettings>

That points to my local nexus server, so'll you'll need to modify it for your environment.

James Moore
  • 8,636
  • 5
  • 71
  • 90
1

Well, I have given up on this and returned to NetBeans 7.1.2 + Scala plugin + Maven. This combination is much better integrated and works out of the box without tinkering.

Christian Schlichtherle
  • 3,125
  • 1
  • 23
  • 47