Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
Created July 31, 2014 20:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaytaylor/af4d4f4bd0004913f7c8 to your computer and use it in GitHub Desktop.
Save jaytaylor/af4d4f4bd0004913f7c8 to your computer and use it in GitHub Desktop.
Scala SBT `build.sbt` example of hooking/injecting arbitrary shell commands and using non-native libraries in the build definition via a task run after successful compilation.
organization := "org.foo.bar"
name := "JustAnExample"
version := "1.0"
scalaVersion := "2.10.3"
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")
val foobar = taskKey[Unit]("foobar")
foobar := {
// Run a shell command and print output.
val process = java.lang.Runtime.getRuntime().exec("ls -al /");
val reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()))
while (reader.ready()) {
println(reader.readLine())
}
// Downlaoad files from S3.
val auth = new com.amazonaws.auth.BasicAWSCredentials(java.lang.System.getenv("AWS_ACCESS_KEY"), java.lang.System.getenv("AWS_SECRET_KEY"))
val client = new com.amazonaws.services.s3.AmazonS3Client(auth)
val myFile = new File("/tmp/myFile")
client.getObject(new com.amazonaws.services.s3.model.GetObjectRequest(System.getenv("AWS_S3_BUCKET_NAME"), fileName), myFile)
}
// Trigger after compilation.
foobar <<= foobar triggeredBy (compile in Compile)
// @see http://www.scala-sbt.org/0.13.5/docs/Extending/Plugins.html
libraryDependencies += "com.amazonaws" % "aws-java-sdk" % "1.6.12"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment