Skip to content

Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations. Serialization/deserialization framework.

License

Notifications You must be signed in to change notification settings

TheElectronWill/night-config

Repository files navigation

Night Config

Maven Central Javadocs Build Status

Introduction

NightConfig is a powerful yet easy-to-use java configuration library, written in Java 8.

It supports the following formats:

How to use

  • Code examples are available here. Note: these examples are for the last stable version, and may not work with the master branch.
  • You can also read the wiki.

Glimpse

// Simple builder:
FileConfig conf = FileConfig.of("the/file/config.toml");

// Advanced builder, default resource, autosave and much more (-> cf the wiki)
CommentedFileConfig config = CommentedFileConfig.builder("myConfig.toml").defaultResource("defaultConfig.toml").autosave().build();
config.load(); // This actually reads the config

String name = config.get("username"); // Generic return type!
List<String> names = config.get("users_list"); // Generic return type!
long id = config.getLong("account.id"); // Compound path: key "id" in subconfig "account"
int points = config.getIntOrElse("account.score", defaultScore); // Default value

config.set("account.score", points*2);

String comment = config.getComment("user");
// NightConfig saves the config's comments (for TOML and HOCON)

// config.save(); not needed here thanks to autosave()
config.close(); // Close the FileConfig once you're done with it :)

Project building

NightConfig is built with Gradle. The project is divided in several modules, the "core" module plus one module per supported configuration format.

The releases are available on Maven Central and JitPack.

Android

Older versions of Android don't provide the packages java.util.function and java.nio.file, which NightConfig heavily uses. If you encounter issues on android you can use the special version that I've made for you by adding _android to the modules' names.

Please read the wiki for more information.

Repo branches

The repository has several branches: