scalapureconfig

Pureconfig - is it possible to include in conf file another conf file?


Is it possible to include in *conf file another conf file?

Current implementation:

// db-writer.conf
writer: {
  name="DatabaseWriter",
  model="model1",
  table-name="model1",
  append=false,
  create-table-file="sql/create_table_model1.sql",
  source-file="abcd.csv"
}

Desired solution:

// model1.conf + others model2.conf, model3.conf..
table: {
 name="model1",
 table-name="model1",
 create-table-file="../sql/create_table_model1.sql"
}

//db-writer.conf
import model1.conf       <=== some import?
writer: {
  name="DatabaseWriter",
  model="model1",        <=== some reference like this?
  append=false,
  source-file="abcd.csv"
}

Reason why I would like to have it like this is :

I guess it is not possible - if not do you have any suggestion how to separate configs & reuse them?

I'm using scala 2.12 lang and pureconfig 0.14 (can be updated to any newer)


Solution

  • Pureconfig uses HOCON (though some of the interpretation of things like durations differ). HOCON include is supported.

    So assuming that you have model1.conf in your resources (e.g. src/main/resources), all you need in db-writer.conf is

    include "model1"
    

    HOCON-style overrides and concatenation are also supported:

    writer: ${table} {
      name = "DatabaseWriter"
      model = "model1"
      append = false
      source-file = "abcd"
    }