14

I know if I add withSources when I define one dependency, sbt can download that sources jar file automatically. For example,

val specs = "org.scala-tools.testing" % "specs_2.8.1" % "1.6.6" % "test" withSources ()

But for the scala-library.jar and scala-compiler.jar, I don't need define them explicitly, how can I get sbt download their sources for me? So, I don't need config it manually after generate idea project using sbt-idea-plugin.

Macyou
  • 143
  • 1
  • 4

3 Answers3

11

You have to change the boot properties. There is a nice description in the recent blog decodified from Mathias:
"How to make SBT download scala library sources" (started from @hseeberger key starting points)


Here is the relevant part (in case that link ever goes stale)

First, forget about trying to find some “hidden” setting in your SBT project definition enabling Scala library source download! It does not exist (at least not in SBT version 0.7.x).
Rather, there are these two things you need to do in order to whip SBT into submission:

  1. Create an alternative configuration file for your SBT launcher.
  2. Make the SBT launcher use it.

These are the steps in detail:

  • Find your sbt-launcher-0.7.x.jar file.
    Since I’m on OS/X and use SBT via Homebrew mine lives at /usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt-launch-0.7.5.RC0.jar.
  • Extract the sbt.boot.properties from the sbt sub directory in the launcher jar
  • Fire up your favorite editor and change line 3 to classifiers: sources (uncomment the line)
  • Find the sbt script file you created during your SBT setup (e.g. ~/bin/sbt, or, when using Homebrew, /usr/local/Cellar/sbt/0.7.x/bin/sbt)
  • Add the path to your tweaked sbt.boot.properties file, prepended with an ’@’ character and in double quotes, as the second-to-last argument of the java call.

This is what my sbt script file looks like:

#!/bin/sh
java -Xmx768M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m \
     -jar /usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt-launch-0.7.5.RC0.jar \
     "@/usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt.boot.properties" \
     "$@"

Once you have completed these steps SBT should happily download the scala-...-sources.jar files for the Scala compiler and standard library for any new project you create.
To have SBT do this for an existing project, you have to manually delete the project/boot/scala-{version} directory before performing an ‘sbt update’ (SBT does not fetch additional source artifacts if the main jar is already present).

Once you have a custom sbt.boot.properties file, there are also other ways to supply it to the SBT launcher.

See SO question "how do I get sbt to use a local maven proxy repository (Nexus)?"

Community
  • 1
  • 1
Heiko Seeberger
  • 3,702
  • 21
  • 20
  • 1
    +1 for the link, but I want to make sure this ends up in a Stackoverflow Crative Common Data (monthly) Dump (see http://blog.stackoverflow.com/2009/06/stack-overflow-creative-commons-data-dump/). Hence my edit, should you accept it. – VonC Dec 18 '10 at 15:21
0

Based on Michael Slinn comments:

If you are using sbt 0.11.x and above, use this command:

sbt update-sbt-classifiers
Aalkhodiry
  • 2,178
  • 30
  • 25
  • this gets the deps of the sbt project definition itself, which may be using a different version of scala. – fommil Sep 02 '14 at 15:23
0

Two pieces of information.

(1) SBT Documentation http://www.scala-sbt.org/0.13.5/docs/Detailed-Topics/Library-Management.html

and I quote: "To obtain particular classifiers for all dependencies transitively, run the updateClassifiers task. By default, this resolves all artifacts with the sources or javadoc classifier."

This means you should not need to do anything, but you can make it explicit and put in you build.sbt: transitiveClassifiers := Seq("sources", "javadoc")

To actually get the sources downloaded by SBT then you do:

"updateClassifiers"

(2) If you are working with Eclipse scala IDE - most likely you are as development of plugins for Eclipse/Netebeans is a lot more active for eclipse - then you should configure your ecplise to find out the sources if you do the following. EclipseKeys.withSource := true Here is the documentation you should read, https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse

99Sono
  • 3,554
  • 27
  • 39