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

前端 未结 5 981
执念已碎
执念已碎 2020-12-30 23:02

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         


        
相关标签:
5条回答
  • 2020-12-30 23:23

    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.

    0 讨论(0)
  • 2020-12-30 23:26

    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.

    0 讨论(0)
  • 2020-12-30 23:35

    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.

    0 讨论(0)
  • 2020-12-30 23:41

    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.

    0 讨论(0)
  • 2020-12-30 23:44

    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.

    0 讨论(0)
提交回复
热议问题