This library provides a barebones method for pulling application configuration from a YAML file.
- Load from classpath
- Load from filesystem
- Load from URL
- Environment/system override*
Environment can only override values which are present.
Import library (build.gradle.kts
)
implementation("com.github.djcass44:simpleconfig:0.1")
Define a schema
data class MyConfig(
val value1: String,
val value2: String,
val value3: Int,
val value4: Boolean
)
Load the configuration
val config = ConfigLoader(MyConfig::class.java).load("classpath:development.yaml")
Files are loaded in the following priority:
- User specified
- Classpath
application.yaml/yml
Loading from filesystem
This is the default method for locating a file.
val config = ConfigLoader(MyConfig::class.java).load("/opt/myapp/config/production.yml")
Loading from URL
Any schema supported by URL::openStream
should work, however only http://
and https://
have been tested.
Example:
val config = ConfigLoader(MyConfig::class.java).load("https://example.org/config/dev.yaml")
Loading from classpath
Prefixing classpath:
will indicate that the file should be loaded from the classpath.
Example:
val config = ConfigLoader(MyConfig::class.java).load("classpath:development.yaml")
This project is licensed under the Mozilla Public License Version 2.0. Please see LICENSE for more information.