Skip to content

Instantly share code, notes, and snippets.

@dcsobral
Created March 25, 2015 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcsobral/d0aedacb274ecf8c9509 to your computer and use it in GitHub Desktop.
Save dcsobral/d0aedacb274ecf8c9509 to your computer and use it in GitHub Desktop.
import sbt.Keys._
import sbt._
import java.nio.file.Files
object TempDir extends AutoPlugin {
object autoImport {
lazy val tempDir = taskKey[File]("Sets target.temp.directory Java property. Creates the directory if needed.")
}
import autoImport._
val tempDirSetting = tempDir := {
val file = target.value / "tmp"
Files.createDirectories(file.toPath)
// The following is SHARED between all non-forked tests, which makes the actual
// value used by a test non-deterministic when running root/test or root/it:test
System.setProperty("target.temp.directory", file.getAbsolutePath)
file
}
override def projectSettings = Seq(
tempDirSetting,
test in Test <<= (test in Test) dependsOn tempDir,
javaOptions in Test += s"-Dtarget.temp.directory=${tempDir.value}"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment