Skip to content

Instantly share code, notes, and snippets.

@karlroberts
Last active October 22, 2019 22:54
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 karlroberts/2ae14ce2b7b48b745d0cd3c5a3a5c620 to your computer and use it in GitHub Desktop.
Save karlroberts/2ae14ce2b7b48b745d0cd3c5a3a5c620 to your computer and use it in GitHub Desktop.
Shows code where pureconfig 0.12.1 ConfigSource.resources(...) fails
// when env = "dev"
// and I have a file called ./src/main/resources/application-dev.conf on my classpath
def forEnvironment(env: String): Configuration = {
val envSpecificConfigPath = "/application-" + env + ".conf"
val conf =
if (getClass.getResource(envSpecificConfigPath) != null &&
System.getProperty("config.resource") == null &&
System.getProperty("config.file") == null) {
// execution path comes in here for resource "/application-dev.conf"
System.setProperty("config.resource", "application-" + env + ".conf")
// This works OK :-)
val url = getClass.getResource(envSpecificConfigPath).toURI.toURL
ConfigSource.url(url).withFallback(ConfigSource.default)
// the following commented code fails
/*
ConfigSource
.resources(envSpecificConfigPath)
.withFallback(ConfigSource.default)
*/
} else {
ConfigSource.default
}
...
conf.at("conf").loadOrThrow[Configuration]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment