forked from softprops/assembly-sbt
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from d40cht/master
Caching the contents of jars on disk from run-to-run
- Loading branch information
Showing
19 changed files
with
204 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
### Speed improvements: Additional caching option, new cacheOutput behaviour | ||
|
||
* Assembly unzips each dependency jar before re-assembling the contents of each jar (and the build classfiles) into a single jar. Previously this happened again for each assembly run, but now the result of the unzip is cached from run-to-run. This provides good performance improvements, especially for systems with slower IO. The new boolean option `cacheUnzip in assembly` (default `true`) can be set to false to disable this behaviour. | ||
* In addition, the behaviour of `assemblyCacheOutput` has been modified. Previously, the contents of each dependency jar would be extracted and then each contained file would be sha1 hashed to determine whether the assembly jar needed rebuilding. Now the jar itself is hashed (significantly quicker) to determine whether assembly needs to be re-run. | ||
* In combination, these two options can reduce the run-time of the second invokation of assembly (when nothing has changed) by up to 5 times on sample test projects. | ||
|
||
Example run-times for a large-ish build, with multiple (eleven) projects with assembly target are below. The commands run for each build were: `;clean;package` (untimed) and then three runs of `assembly`: | ||
|
||
## 0.9.0 | ||
Run number | No caching | Cache unzip | Cache unzip + cache output | ||
---- | --- | --- | --- | ||
1st | 99s | 101s | 85s | ||
2nd | 119s | 34s | 12s | ||
3rd | 102s | 32s | 12s | ||
|
||
[83]: https://github.com/sbt/sbt-assembly/pull/83 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import AssemblyKeys._ | ||
|
||
version := "0.1" | ||
|
||
assemblySettings | ||
|
||
scalaVersion := "2.9.1" | ||
|
||
libraryDependencies += "org.scalatest" % "scalatest_2.9.0" % "1.6.1" % "test" | ||
|
||
libraryDependencies += "com.weiglewilczek.slf4s" %% "slf4s" % "1.0.7" | ||
|
||
libraryDependencies += "ch.qos.logback" % "logback-classic" % "0.9.29" % "runtime" | ||
|
||
assemblyCacheUnzip in assembly := true | ||
|
||
assemblyCacheOutput in assembly := false | ||
|
||
unmanagedJars in Compile <++= baseDirectory map { base => | ||
(base / "lib" / "compile" ** "*.jar").classpath | ||
} | ||
|
||
unmanagedJars in Runtime <++= baseDirectory map { base => | ||
(base / "lib" / "runtime" ** "*.jar").classpath | ||
} | ||
|
||
unmanagedJars in Test <++= baseDirectory map { base => | ||
(base / "lib" / "test" ** "*.jar").classpath | ||
} | ||
|
||
excludedJars in assembly <<= (fullClasspath in assembly) map { cp => | ||
cp filter {_.data.getName == "compile-0.1.0.jar"} | ||
} | ||
|
||
jarName in assembly := "foo.jar" | ||
|
||
TaskKey[Unit]("check") <<= (crossTarget) map { (crossTarget) => | ||
val process = sbt.Process("java", Seq("-jar", (crossTarget / "foo.jar").toString)) | ||
val out = (process!!) | ||
if (out.trim != "hello") error("unexpected output: " + out) | ||
() | ||
} | ||
|
||
TaskKey[Unit]("checkhash") <<= (crossTarget, streams) map { (crossTarget, s) => | ||
import java.security.MessageDigest | ||
val jarHash = crossTarget / "jarHash.txt" | ||
val hash = MessageDigest.getInstance("SHA-1").digest(IO.readBytes(crossTarget / "foo.jar")).map( b => "%02x".format(b) ).mkString | ||
if ( jarHash.exists ) | ||
{ | ||
val prevHash = IO.read(jarHash) | ||
s.log.info( "Checking hash: " + hash + ", " + prevHash ) | ||
assert( hash == prevHash ) | ||
} | ||
IO.write( jarHash, hash ) | ||
() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0-+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Main { | ||
def main(args: Array[String]) { println("hello") } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# check if the file gets created | ||
> clean | ||
> assembly | ||
$ exists target/scala-2.9.1/foo.jar | ||
|
||
# run to cache the hash, then check it's consistent | ||
> check | ||
> checkhash | ||
$ exists target/scala-2.9.1/jarHash.txt | ||
> checkhash | ||
|
||
> assembly | ||
$ newer target/scala-2.9.1/foo.jar target/scala-2.9.1/jarHash.txt | ||
> check | ||
|
||
# run again to check that the hash is the same | ||
# when the unzipped jars are read from cache | ||
# on disk | ||
> checkhash | ||
$ newer target/scala-2.9.1/jarHash.txt target/scala-2.9.1/foo.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.8-+") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0-+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# check if the file gets created | ||
> test:assembly | ||
$ exists target/foo.jar | ||
$ exists target/scala-2.9.1/foo.jar | ||
|
||
# check if it says hello | ||
> check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.8-+") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0-+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.8-+") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0-+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.8-+") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0-+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.8-+") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0-+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.8-+") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0-+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.8-+") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0-+") |
Oops, something went wrong.