Daniel Daniel - 1 month ago 3
Scala Question

SBT: possible to read a variable from disk?

Is it possible to read contents of file inside sbt?
Say reading a username-pass, etc.


Yes, you can read files inside SBT. Look at this example (suppose you have a case class AppCredentials defined somewhere in your project):

case class AppCredentials(userName: String, pwd: String) // it's better to use Array[Char] for password
val appCredentials = settingKey[AppCredentials]("The application credentials")

appCredentials := {
  val creds = IO.readLines(new File(Path.userHome.absolutePath + "/.credentials"))
  val (user, pwd) = parseCredentials(creds)
  AppCredentials(user, pwd)

name := appCredentials.value.userName