Compile the Scala Standard Library

Hello,

I would like to compile the Scala Standard Library and obtain a file like the well-known scala-library.jar. After that, I would like to alter the source code of the Scala Standard Library and recompile it, in order to see what the effects are.

How would I do that?

So far, I did the following:

git clone https://github.com/scala/scala.git
cd scala
sbt compile

I got a whole lot of warnings, but the thing finished successfully:

[success] Total time: 168 s (02:48), completed 27.10.2020, 23:54:53

Alvin Alexander helped me: Scala/SBT: How to deploy a single, executable Jar file (sbt-assembly).
I also found Baeldung’s Creating a Fat JAR Using SBT helpful.

Following Alvin, I added addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0") in the file project/plugins.sbt and executed sbt assembly.
The file number count in the obtained .jar file is identical to the file number count of scala-library.jar, 2897 files, but the .jars are not identical. Are there some optimization flags that are used to generate the latter file?

I wonder why one would want an executable or a fat JAR for a library? Usually, if you want a JAR for a library, you can do publishLocal in SBT and find the JAR file in your target directory.

Side note: if I want to package my Scala app, I usually use the SBT Native Packager to get a DEB file I can install (or remove or upgrade) with apt on Ubuntu just like any other app.

2 Likes

The readme of the scala repo contains pretty good info on how to build scala, and how to make and test changes.

2 Likes