Search code examples
javascalatypesafe-config

Prohibit resolving during loading in typesafe config


I want to prohibit resolving of a.b. I want to substitute param from another config. Like this:

val d = ConfigFactory.load(ConfigFactory.parseString(
    """
      |param = x
      |a.b = ${param}
    """.stripMargin))

val a = ConfigFactory.parseString("param = 1")

val result = a.withFallback(d).resolve()

In this case param gets value 1, but a.b remains x I've tried to set ConfigResolveOptions.defaults().setAllowUnresolved(true) when loading config d, but that doesn't work.

How can I overcome this?


Solution

  • Found a workaround for my problem:

    So If I have config file application.conf which uses include to include config files which contain substitution syntax and files which contain declaration of the config values which are going to be substituted.

    val a = ConfigFactory.parseString(s"""param = 1""")
     val z = ConfigFactory.parseResources("application.conf") //this doesn't resolve substitutions
    
    val result = a.withFallback(z).resolve().withFallback(ConfigFactory.load("application.conf"))