typesafe-config

ENV VAR in HOCON include statement


I'd like to do the following

include file(${HOME}/.oat/db_local_dev.conf)

Unfortunately, it gives the following error:

Caused by: com.typesafe.config.ConfigException$Parse: /Users/XXXX/src/oat3/conf/shared.local.conf: 16: expecting a quoted string inside file(), classpath(), or url(), rather than: '${'HOME'}'

The documentation at https://github.com/typesafehub/config does not say the argument to include must be a string, but I think I remember reading that someplace in the past.

So... Any workarounds? If not, can someone at least explain why this limitation is here? Some sort of security hole? It's the only reason I can think of for omitting such a useful feature.

Thanks.


Solution

  • You cannot dynamically include another properties file.

    An include statement consists of the unquoted string include followed by whitespace and then either:

    • a single quoted string which is interpreted heuristically as URL, filename, or classpath resource.
    • url(), file(), or classpath() surrounding a quoted string which is then interpreted as a URL, file, or classpath. The string must be quoted, unlike in CSS.
    • required() surrounding one of the above

    see official docs: https://github.com/lightbend/config/blob/master/HOCON.md#includes

    Also see (Feature request: dynamic includes #122): https://github.com/lightbend/config/issues/122