joesan
joesan

Reputation: 15435

SBT Application Confg is Not Overwritten

I have a sbt spark application where I'm using Typesafe config to load environment variables. I have in my src/main/resources a config file called application.conf which contains the default values for all of the application. The application.conf looks like this:

# The environment representation of the configurations
# ~~~~~
env = "default"

# Represents the location details of the input and output files
# ~~~~~
data {
    file.name = "housing.tgz"
    file.source.url = "data/"${file.name}

    # Data related configurations
    training.ratio = 0.2
}

I then have in my src/test/resources another test specific configuration file called application.test.conf where I have the following:

include "application.conf"

# The environment representation of the configurations
# ~~~~~
env = "test"

data {
  file.name = "housing.tgz"
  file.target.path = "data/tmp/"
  #file.target.path = ${?FILE_TARGET_PATH}
}

Since my project is hosted on GitHub, I'm using GitHub actions to trigger my CI run, but this fails with the reason that it cannot find data.file.source.url which is already defined in the base application.conf

I even have the following set it my build.sbt:

javaOptions in Test += s"-Dconfig.file=${sourceDirectory.value}/test/resources/application.test.conf"

I seriously do not understand why this should not work. I hate to duplicate entries in my application.test.conf. How do I get this resolved?

EDIT: This is how I load:

def getConfigSource: ConfigSource = {
    println(s"System get Property ************************ ${System.getProperty("config.file")}")
    Option(System.getProperty("config.file")) match {
      case Some(path) if new File(path).exists() =>
        ConfigSource.FromFile(path)

      case _ =>
        val opt1 = Option(System.getProperty("ENV", "")).filter(_.nonEmpty)
        val opt2 = Option(System.getProperty("env", "")).filter(_.nonEmpty)

        opt1.orElse(opt2) match {
          case Some(envName) =>
            val name = s"application.${envName.toLowerCase}.conf"
            ConfigSource.FromResource(name)
          case None          =>
            println("Loading default from Resource **************** ")
            ConfigSource.FromResource("application.conf")
        }
    }
  }

Upvotes: 0

Views: 238

Answers (0)

Related Questions