Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I let sbt download the source of scala-library.jar?

Tags:

scala

sbt

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.

like image 488
Macyou Avatar asked Dec 18 '10 09:12

Macyou


People also ask

Where does sbt download Scala?

Having said that, at the very beginning, sbt will always download its own internal dependencies, Scala including. It is then saved in ~/. sbt/boot . p.s. The versions of Scala used by sbt internally are not at all different from the ones you may have downloaded already for your Scala/sbt projects.

How do I run a JAR file in sbt?

Solution. Create a directory layout to match what SBT expects, then run sbt compile to compile your project, sbt run to run your project, and sbt package to package your project as a JAR file. Unlike Java, in Scala, the file's package name doesn't have to match the directory name.

Does sbt install Scala?

sbt will download Scala for you. If you install sbt-extras (basically just a script) you don't even need to download sbt : it will automatically download the sbt launcher you need. Very handy since you just need to specify sbt. version in your build.

Does sbt include Scala?

sbt's Scala versionsbt needs Scala jars to run itself since it is written in Scala. sbt uses that same version of Scala to compile the build definitions that you write for your project because they use sbt APIs.


1 Answers

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

like image 100
Heiko Seeberger Avatar answered Sep 28 '22 08:09

Heiko Seeberger