Tagged Modular Configuration

Configuration library. Can composite modules together and further composite with tags

License

License

GroupId

GroupId

io.github.yeagy
ArtifactId

ArtifactId

tmc
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Tagged Modular Configuration
Configuration library. Can composite modules together and further composite with tags
Project URL

Project URL

https://github.com/yeagy/tmc
Source Code Management

Source Code Management

https://github.com/yeagy/tmc

Download tmc

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.yeagy/tmc/ -->
<dependency>
    <groupId>io.github.yeagy</groupId>
    <artifactId>tmc</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.yeagy/tmc/
implementation 'io.github.yeagy:tmc:0.2.0'
// https://jarcasting.com/artifacts/io.github.yeagy/tmc/
implementation ("io.github.yeagy:tmc:0.2.0")
'io.github.yeagy:tmc:jar:0.2.0'
<dependency org="io.github.yeagy" name="tmc" rev="0.2.0">
  <artifact name="tmc" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.yeagy', module='tmc', version='0.2.0')
)
libraryDependencies += "io.github.yeagy" % "tmc" % "0.2.0"
[io.github.yeagy/tmc "0.2.0"]

Dependencies

compile (4)

Group / Artifact Type Version
io.github.lukehutch : fast-classpath-scanner jar 2.21
com.fasterxml.jackson.core : jackson-databind jar 2.8.5
com.fasterxml.jackson.dataformat : jackson-dataformat-yaml jar 2.8.5
ru.vyarus : generics-resolver jar 3.0.0

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.projectlombok : lombok jar 1.16.12

Project Modules

There are no modules declared in this project.

Build Status Maven Central Javadocs

Tagged Modular Configuration

  • Java configuration library. Read and map your config file(s) to a POJO.
  • Modular: Reference other config files on the classpath to merge into your config.
  • Tagged: Define config blocks with tags to merge config at runtime.
  • Formats: JSON and YAML

Usage:

    MyConfig config = TaggedModularConfig.rootModule("main").applyTags("prod").create(MyConfig.class);
  • TMC modules have filename patterns <module name>.tmc.<format> (ex: main.tmc.json, config.tmc.yml)
  • Modules are referenced using the "_module" field name. The module file will be loaded and merged into the node the "_module" was found on.
  • Tags are defined on a module root using the "_tags" field name. Tags specified at runtime will be merged onto the module at the root level, so full paths are needed in tag blocks.
  • TMC modules can reference other modules. TMC will resolve modules recursively, and error if a cycle is detected. Tags can also contain modules.
  • Collision precedence order: root tags > root tree > module tags > module tree. Module tags will be resolved before the module is merged into it's parent tree. Module merging will not overwrite existing leafs of the parent module. Tag merging will overwrite existing leafs of the parent module. Multi-tag collisions will be won by the firstmost tag of the applied tag list.
//main.tmc.json
{
  "app": "example",
  "logging": {
    "level": "DEBUG",
    "enabled": true
  },
  "http": {
    "_module": "loadbalancer",
    "port": 8080
  },
  "_tags": {
    "prod": {
      "logging": {
        "level": "WARN"
      }
    }
  }
}
//loadbalancer.tmc.json
{
  "host": "localhost",
  "timeout": "5s",
  "_tags": {
    "prod": {
      "host": "lb.site.com"
    }
  }
}

Running TMC on the "main" module with the "prod" tag would create the config below.

{
  "app": "example",          //root tree
  "logging": {               //root tree
    "level": "WARN",         //root tag
    "enabled": true          //root tree
  },
  "http": {                  //root tree
    "host": "lb.site.com",   //module tag
    "timeout": "5s",         //module tree
    "port": 8080             //root tree
  }
}
<dependency>
  <groupId>io.github.yeagy</groupId>
  <artifactId>tmc</artifactId>
  <version>0.2.0</version>
</dependency>

Versions

Version
0.2.0
0.1.0