Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nohus/autokonfig

Kotlin configuration library with batteries included
https://github.com/nohus/autokonfig

configuration hocon json kotlin library

Last synced: 25 days ago
JSON representation

Kotlin configuration library with batteries included

Awesome Lists containing this project

README

        

# AutoKonfig

[![AutoKonfig](https://autokonfig.nohus.dev/images/AutoKonfig.png)](https://autokonfig.nohus.dev/)

Kotlin configuration library with batteries included.

[![License](https://img.shields.io/badge/license-Apache%202%20-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)
[![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://github.com/Nohus/AutoKonfig/tree/master/src/test/kotlin/dev/nohus/autokonfig)
[![Version](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fdev%2Fnohus%2FAutoKonfig%2Fmaven-metadata.xml)](https://search.maven.org/artifact/dev.nohus/AutoKonfig)

## Website
[https://autokonfig.nohus.dev/](https://autokonfig.nohus.dev/)

## Features overview
- Support for JSON, [HOCON](https://autokonfig.nohus.dev/hocon) and Java properties config files
- Loading config files from resources and remote URLs
- Reading configuration from system properties and environment variables
- Parsing command-line parameters
- Merging properties loaded from multiple sources
- Automatically finding config files
- Type-safe properties
- Support for default and optional values
- Many useful [property types](https://autokonfig.nohus.dev/types), including dates (`2020-02-02`), times (`10:15:30`), durations (`20s`) and memory sizes (`256 MB`)
- Type-specific parsing, a value of `1` can be the string `"1"`, the integer `1`, or the boolean `true`
depending on which type is asked for
- Collection types
- 100% unit test coverage

## Quick start

#### Gradle
``` Groovy
implementation "dev.nohus:AutoKonfig:1.1.0"
```

#### Maven
``` XML

dev.nohus
AutoKonfig
1.1.0

```

The artifacts are available on Maven Central.

## Simple example

Create a config file:

#### app.conf
``` Lighttpd
host = nohus.dev
port = 80
```

Create variables for your properties:

#### Main.kt
``` Kotlin
fun main() {
val host by StringSetting()
val port by IntSetting()
println("Host: $host, port: $port")
}
```

That's it! AutoKonfig automatically loaded your config file, because it had a [well-known name](https://autokonfig.nohus.dev/#supported-file-types). It knew which properties to load based on the variable names, and it mapped them to types based on the specified `StringSetting` and `IntSetting` delegates.

To see more, [continue reading on the website](https://autokonfig.nohus.dev/).