Skip to content

Modules and dependencies

Guillaume Raffin edited this page Oct 14, 2019 · 14 revisions

The modules

Night-Config is divided into several gradle modules: the core modules, plus one module per configuration language.

If you only work in memory, you only need the core module. However, if you want to read and write config files, you also need the module(s) corresponding to your config language: json, toml, hocon, yaml. Note that those modules automatically include the core.

Configure your build tool

Simply add the module(s) you need, for instance toml, as a dependency from Maven Central.

Gradle

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.electronwill.night-config:toml:3.6.0'
}

Maven

<dependency>
    <groupId>com.electronwill.night-config</groupId>
    <artifactId>toml</artifactId>
    <version>3.6.0</version>
</dependency>
object yourModule extends ScalaModule {
  def ivyDeps = Agg(ivy"com.electronwill.night-config:toml:3.6.0")
}

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 with the NightConfig on android, you can use the special version that I've made for you: in your dependencies' declaration, simply append _android at the end of the NightConfig modules.

Example (gradle):

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.electronwill.night-config:toml_android:3.6.0'
    compile 'com.electronwill.night-config:json_android:3.6.0'
}

Limitations of the android version

When using core_android or any of the *_android NightConfig module, most of the features should work just as usual. Here are the known limitations:

Limitation Why Notes
The Supplier and Consumer classes aren't those from the JDK but from com.electronwill.nightconfig.core.utils Android below api 24 doesn't provide the standard Supplier and Consumer You can still use lambdas
There is no asynchronous FileConfig. All the FileConfigs are synchronous, even if sync() is not called on the FileConfigBuilder. Android below api 26 doesn't provide the class AsynchronousFileChannel
Autoreloaded configurations are checked every 5 seconds by NightConfig. When the file size and/or last-modified datetime changes, the configuration is reloaded. Android below api 26 doesn't provide the package java.nio.file