Created
June 30, 2012 09:16
-
-
Save anvie/3023066 to your computer and use it in GitHub Desktop.
Gather all dependencies jar and generate start script for running, all placed in `target/` dir
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
lazy val copyDependencies = TaskKey[Unit]("gather-lib") | |
def gatherDeps = copyDependencies <<= (update, crossTarget, scalaVersion, internalDependencyClasspath in Compile, mainClass in Runtime) map { | |
(updateReport, out, scalaVer, deps, main_class) => | |
var projDeps = Array[String]() | |
deps.foreach { | |
depsDir => | |
val x = depsDir.data.getCanonicalPath.split("/") | |
if (x.length > 3){ | |
val projName = x(x.length - 3) | |
println("Copying `" + out / "lib" / projName + "`...") | |
IO.copyDirectory(depsDir.data, out / "lib" / projName) | |
projDeps :+= "lib/" + projName | |
} | |
} | |
updateReport.allFiles foreach { | |
srcPath => | |
val destPath = out / "lib" / srcPath.getName | |
println("Copying `" + destPath + "`...") | |
IO.copyFile(srcPath, destPath, preserveLastModified = true) | |
} | |
// generate executable script start.sh | |
println("Generating start.sh...") | |
val shScript = | |
"""#!/usr/bin/env sh | |
|java "$@" -cp "classes:lib/*:%s" %s | |
""".stripMargin.format(projDeps.reduce(_ + ":" + _), main_class.getOrElse("xxx")).trim + "\n" | |
IO.write(out / "start.sh", shScript.getBytes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add to your project settings:
From sbt console type: