An sbt plugin that enables straight-to-jar compilation of Scala files
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src/main/scala/com/typesafe/sbttojar
.gitignore
LICENSE
README.md
build.sbt

README.md

sbt-tojar

Description

sbt-tojar is a simple sbt plugin that enables straight-to-jar compilation of Scala files while using sbt.

When compiling Scala files, sbt normally writes each generated class to a separate classfile, leading to a potentially rather large number of individual small files. At the end of the compilation process, all of those classfiles are packaged together into a new jar file in order to prepare for publishing.

The intermediate step of creating many individual classfiles can be somewhat slow on those filesystems that are not very efficient at manipulating many small files.

This plugin will make use of scalac's straight-to-jar compilation feature, enabling sbt to avoid the intermediate creation of the separate classfiles.

Usage

  • add to your project/plugin.sbt the line: addSbtPlugin("com.typesafe.sbt" % "sbt-tojar" % "0.3")
  • then add to the settings of the subprojects for which you would like to enable this functionality: straightToJar := true

The straight-to-jar compilation feature can be enabled individually for each subproject, and changed on-the-fly using a set straightToJar in proj := value (a clean may be needed beforehand).

Notes

During the compilation of a mixed Java/Scala project, both the Scala and the Java compilers are called. The Java compiler is unable to produce a jar file directly, therefore initially a first jar is generated by scalac, then the remaining classes created by javac are appended to it.

When running under JDK7 and newer, the plugin is able to open directly the existing jar and append the new classfiles. The facilities used for this operation are not avaliable on JDK6 and older; instead, a less efficient implementation will create a new jar file, copy the entries from the first jar, and finally append the new classes.

Since the packaged jar file is generated from the compiled classes as described above, the archive cannot contain files that are generated from other sources. Therefore, straightTojar is currently incompatible with bytecode manipulations via the manipulateBytecode facility, and the resulting jar archive cannot contain files copied via copyResources. However, in an sbt project that contains many different subprojects, the straight-to-jar compilation can be selectively disabled on just the subprojects that use those features.

It should also be noted that straight-to-jar compilation will disable the usual incremental compilation mechanisms of sbt: if any source file in a straight-to-jar subproject is modified in a way that makes recompilation necessary, then all of the source files of that subproject will be recompiled.

This plugin requires sbt 0.13.10, final or RC2, or a more recent version..