Created
March 25, 2015 20:53
-
-
Save dcsobral/d0aedacb274ecf8c9509 to your computer and use it in GitHub Desktop.
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
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