0

I have this in a .conf file and I want to overwrite the value at index 0 in array field1

database {
  master {
    field1:["a","b","c"]
  }
}

and I run the application via sbt like this:

sbt -Ddatabase.master.field1.0="11.111.11.111:3306" package

then I look inside the jar at the .conf file and nothing is changed.

This guide indicates to change each array element by index instead of the whole array (which I also tried but to no avail): https://salsa.debian.org/java-team/typesafe-config/blob/master/HOCON.md#array-and-object-concatenation

How do you overwrite array elements in HOCONS?

Adrian
  • 5,603
  • 8
  • 53
  • 85

1 Answers1

3

I think the problem is, that your hocon is part of what you try to pack, but the -D will give the params to the JVM of sbt. Why should the config of the sbt's JVM have any influence to the .jar you pack?

Edit
Adrian taught me, that this is actually possible. Still my solution below is what I would prefer. It is explicit and good to understand. Some params and the sbt call seems to me to not be nice and clean.

I guess you want to have an environment specific database config.
You could start the application with your config as you tried with sbt or put all configs for different systems in different hocons and load the hocons depending on the system you start, which you can define by a parameter for the program.
Look at the docs to see how to load additional files.

Nabil A.
  • 3,270
  • 17
  • 29
  • I can overwrite with -D flag any non array parameters – Adrian Jul 09 '19 at 16:32
  • here's a solution I've found: first create env variable `$DBIPPORT` (say in bash) then in .conf fire add this in addition to what I have in my question: `database.master.field1 = [${?DBIPPORT}]` – Adrian Aug 12 '19 at 23:05