1

After reading about Kotlin, and particularly about Kotlin DSL, it seems to be a good way to replace JSON configuration files.

I have a service that takes a configuration file argument (resource), something like --config='path/to/configX.json'.
There are many different configurations to customise and deploy different services for different clients.
The JSON files, although simple, are long, repetitive and error prone.

Kotlin DSL seems to be a good way to simplify these configs, reducing repetition (with builder functions) and having built-in validation of the "code" (unlike JSON that requires custom validations or simply fails deserialising if there are mistakes).

However, I do not see examples of loading different configurations from Kotlin scripts at service startup (ex: --config='path/to/configX.kts').
Is that something possible out of the box?
Something that would be recommended or a misuse of the DSL?

Simple example:

config.json
{
  "castle" : {
    "randomVar": 12,
    "structure": "Titanium"
    ...
  }
}
config.kts
castle {
  randomVar 12
  structure "Titanium"
  ...
}
Thomas
  • 1,053
  • 2
  • 11
  • 20

0 Answers0