Skip to content

A simple configuration management library for any Java project!

License

Notifications You must be signed in to change notification settings

AuthMe/ConfigMe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3649924 Β· Oct 18, 2024
Nov 30, 2023
Oct 5, 2024
Oct 18, 2024
Oct 5, 2024
Oct 5, 2024
Jul 8, 2016
Aug 4, 2023
Sep 12, 2023
Aug 28, 2023
Aug 22, 2023
Jul 8, 2016
Sep 16, 2023
Apr 28, 2024

Repository files navigation

ConfigMe

Build Status Coverage Status Javadocs Code Climate

A simple configuration management library with YAML support out of the box.

  • Lightweight
  • Flexible
  • Out of the box support for YAML
  • Allows migrations / config file checks
  • Null-safe
  • Unit testing friendly

How it works

  • Each configurable value is a Property in ConfigMe. Properties are declared as public static final fields in classes which implement the SettingsHolder interface.
  • Configurations are read from a PropertyResource (e.g. the provided YamlFileResource), which abstracts reading and writing.
  • The property resource may be checked for completeness with the MigrationService, which allows you also to rename properties or to remove obsolete ones.
  • The SettingsManager unifies the members above. On creation, it calls the migration service and allows you to get and change property values.

Integration

Start using ConfigMe by adding this to your pom.xml:

<dependencies>
    <dependency>
        <groupId>ch.jalu</groupId>
        <artifactId>configme</artifactId>
        <version>1.4.1</version>
    </dependency>
</dependencies>

Example

config.yml

title:
    text: 'Hello'
    size: 12

TitleConfig.java

public class TitleConfig implements SettingsHolder {

    public static final Property<String> TITLE_TEXT =
        newProperty("title.text", "-Default-");

    public static final Property<Integer> TITLE_SIZE =
        newProperty("title.size", 10);

    private TitleConfig() {
        // prevent instantiation
    }
}

WelcomeWriter.java

public class WelcomeWriter {
    public String generateWelcomeMessage() {
        SettingsManager settings = SettingsManagerBuilder
            .withYamlFile(Path.of("config.yml"))
            .configurationData(TitleConfig.class)
            .useDefaultMigrationService()
            .create();

        // Get properties from the settings manager
        return "<font size=\""
            + settings.getProperty(TitleConfig.TITLE_SIZE) + "\">"
            + settings.getProperty(TitleConfig.TITLE_TEXT) + "</font>";
    }
}

πŸ“ Read the full documentation in the ConfigMe Wiki.

πŸ“ See a full working example based on this here.

πŸ“ See how to use custom classes as property types in the bean properties demo.