AuthMe / ConfigMe

A simple configuration management library for any Java project!
MIT License
37 stars 14 forks source link
config-management configme configuration configuration-management java properties properties-loader settings-storage yaml-configuration yaml-exporter

ConfigMe

Build Status Coverage Status Javadocs Code Climate

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

How it works

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>";
    }
}

:pencil: Read the full documentation in the ConfigMe Wiki.

:pencil: See a full working example based on this here.

:pencil: See how to use custom classes as property types in the bean properties demo.