There’s a rather handy little library I’ve built a couple of times, and have decided to rewrite and bequeath to the open source community – i.e. me in the future on another project that needs this.
You can check it out here.
The problem I want to solve is that of loading configuration values from the environment into a Java program. We may wish to configure our applications to have various externalised values. Many of these, like tuning parameters, will be hardcoded in a config file somewhere at dev time, and only get tweaked when absolutely necessary.
Other values may get manipulated at deployment time, e.g. addresses of neighbouring services, or passwords.
While frameworks like Spring do this really well, and are not worth second guessing, there are two situations where Spring is too heavy a solution:
- Some sort of test pack that just needs to know where the system under test is, or which browser to use
- Very lightweight applications like AWS Lambdas
DropWizard has a very nice YML format which allows the interpolation of environment variables and system properties into the loaded configuration. I had rather hoped this library could be stolen and used outside of DropWizard, but it seems to be baked in.
So I present
lightweight-config a very simple YML file loader. It expects to find a YML file in the program’s resources, and it inspects each line of the file for placeholders which it attempts to populate from the environment or system properties.
It also supports importing other files, and it allows placeholders to define defaults. When used in conjunction with other bits of YML syntax like
!!int it can powerfully express most configurations I’ve come across.
If you have this problem, then maybe you’ll find it solvable with this library.