Last active
October 22, 2019 22:54
-
-
Save karlroberts/2ae14ce2b7b48b745d0cd3c5a3a5c620 to your computer and use it in GitHub Desktop.
Shows code where pureconfig 0.12.1 ConfigSource.resources(...) fails
This file contains hidden or 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
// 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