diff --git a/README.md b/README.md index e3a0d13..3c90e84 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ MY_CERT="-----BEGIN CERTIFICATE----- Variable expansion of the form `$FOO` and `${FOO}` is supported based on the values in `.env` or the system environment. ### Change file name -It is possible to change the file name `.env` +It is possible to override the default file name `.env`. It will be treated as an absolute path if it starts with a `/`, and as a relative path to base directory of this project otherwise. ``` ThisBuild / envFileName := "dotenv" ``` diff --git a/src/main/scala/au/com/onegeek/sbtdotenv/SbtDotenv.scala b/src/main/scala/au/com/onegeek/sbtdotenv/SbtDotenv.scala index fb2cf02..1f63cfe 100644 --- a/src/main/scala/au/com/onegeek/sbtdotenv/SbtDotenv.scala +++ b/src/main/scala/au/com/onegeek/sbtdotenv/SbtDotenv.scala @@ -84,9 +84,10 @@ object SbtDotenv extends AutoPlugin { fileName: String ): Option[Map[String, String]] = { val baseDirectory = state.configuration.baseDirectory + val filePath = if (fileName.startsWith("/")) fileName else s"${baseDirectory}/${fileName}" state.log.debug(s"Base directory: ${baseDirectory}") - state.log.debug(s"looking for .env file: ${baseDirectory}/${fileName}") - val dotEnvFile: File = new File(s"${baseDirectory}/${fileName}") + state.log.debug(s"looking for .env file: ${filePath}") + val dotEnvFile: File = new File(filePath) parseFile(dotEnvFile).map { environment => state.log.info( s".env detected (fileName=${fileName}). About to configure JVM System Environment with new map"