How to attach sources to SBT managed dependencies in Scala IDE?

守給你的承諾、 提交于 2019-11-30 08:09:48

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.

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.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!