Play 2.1 ConfigFactory.parseFile cannot be replaced

In application.conf (in Play 2.0.4, sbt 0.11.3) I could use the following substitutions:

app {
  major = 0
  minor = 1
  revision = 62
  date = 0127
  version = ${app.major}.${app.minor}.${app.revision}.${app.date}
}

      

After upgrading to version 2.1.0 and sbt 0.12.2 and using that for Build.scala,

val conf = ConfigFactory.parseFile(new File("conf/application.conf"))

      

I am getting error when I do play clean

:

Caused by: com.typesafe.config.ConfigException$NotResolved: need to call resolve() on root config; tried to get value type on an unresolved substitution: ConfigSubstitution(${app.major}"."${app.minor}"."${app.revision}"."${app.date})
    at com.typesafe.config.impl.ConfigSubstitution.valueType(ConfigSubstitution.java:54)
    at com.typesafe.config.impl.DefaultTransformer.transform(DefaultTransformer.java:15)
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:118)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:135)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:140)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:108)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:146)
    at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:188)
    at ApplicationBuild$.<init>(Build.scala:12)
    at ApplicationBuild$.<clinit>(Build.scala)

      

Based on the replay configuration documentation, this type of substitution should be supported:

Implementations must take care to allow objects to reference paths within themselves. For example, this should work:

bar: {foo: 42, baz: $ {bar.foo}} Here, if the implementation allowed all substitutions on the bar as part of the substitution resolution $ {bar.foo}, it would be a loop. The implementation should only resolve the foo field in the bar, not recursively the entire panel object.

Any ideas how to fix this?

+3


source to share


2 answers


Your syntax is correct. It seems that you really need to call resolve (), as the error message says, to resolve the replacements. My guess is that in 2.0.x the replay framework did this and provided a config that was already resolved this way. Now that the configuration API is used directly, it needs to be manually resolved.

Add a call resolve()

on this line:



val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve()

      

+3


source


AFAIK, my understanding of the document is that you should use something like:

app {
  major = 0
  minor = 1
  revision = 62
  date = 0127
  version = ${major}.${minor}.${revision}.${date}
}

      



I haven't tested it ...

Or maybe it worked under 2.0.4 due to a bug?

0


source







All Articles