Kotlin configuration library with batteries included

Overview

AutoKonfig

AutoKonfig

Kotlin configuration library with batteries included.

License Coverage Version

Website

https://autokonfig.nohus.dev/

Features overview

  • Support for JSON, 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
  • Many useful property 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

implementation "dev.nohus:AutoKonfig:1.0.3"

Maven

<dependency>
    <groupId>dev.nohus</groupId>
    <artifactId>AutoKonfig</artifactId>
    <version>1.0.3</version>
</dependency>

The artifacts are available on Maven Central.

Simple example

Create a config file:

app.conf

host = nohus.dev
port = 80

Create variables for your properties:

Main.kt

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. 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.

You might also like...
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀

Fast Android Networking Library About Fast Android Networking Library Fast Android Networking Library is a powerful library for doing any type of netw

Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.

AndroidAsync AndroidAsync is a low level network protocol library. If you are looking for an easy to use, higher level, Android aware, http request li

Java HTTP Request Library

Http Request A simple convenience library for using a HttpURLConnection to make requests and access the response. This library is available under the

Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: !-- Pull in as a traditional dependency -- dependency groupIdcom.konghq/groupId artifactIdunire

The best file downloader library for Android
The best file downloader library for Android

Overview Fetch is a simple, powerful, customizable file download manager library for Android. Features Simple and easy to use API. Continuous download

No Internet Layout Library 2.5 0.0 Java #layout #check_internet

No Internet Layout Library Library to check internet connection and change layout to no internet layout if there is no internet. Gradle: allprojects {

:satellite: [Android Library] Simplified async networking in android
:satellite: [Android Library] Simplified async networking in android

Android library that simplifies networking in android via an async http client. Also featured in [Awesome Android Newsletter #Issue 15 ] Built with ❤︎

super simple library to manage http requests.

HttpAgent super simple library to manage http requests. Gradle dependencies { implementation 'com.studioidan.httpagent:httpagent:1.0.16@aar' } No

Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: !-- Pull in as a traditional dependency -- dependency groupIdcom.konghq/groupId artifactIdunire

Comments
  • Add java 8 support

    Add java 8 support

    Hi,

    I'm getting an exception java.lang.NoSuchMethodError: java.lang.Class.getPackageName()Ljava/lang/String; when creating an instance of AutoKonfig using AutoKonfig().withProperties(properties), which is coming from https://github.com/Nohus/AutoKonfig/blob/70035ebf9303dacacc6404507dbf873db2af5915/src/main/kotlin/dev/nohus/autokonfig/utils/SourceUtil.kt?rgh-link-date=2022-04-19T18%3A14%3A11Z#L17

    I'm assuming this is because getPackageName() method was introduced in java 9 which makes it incompatible with java 8 or lower. Although you seem to have java compatibility set to 1.8 in build.gradle, it appears that you're actually using a later java version for compilation?

    I've also made a PR that should fix this issue - #3 . The existing tests are passing fine, not sure if any new tests should be added though.

    opened by serpro69 1
  • Optional settings with null value as default

    Optional settings with null value as default

    Currently, there is no way to create an "optional" setting with a null default value, as null is the same value used to indicate that a setting has no default value, and throwing an exception if the value is missing.

    This forces you to define settings like this:

    object ProxyConfig: Group("proxy") {
        val url by StringSetting("")
        val port by IntSetting(0)
    }
    

    And then validate them like this:

    if (ProxyConfig.url.isNotBlank() && ProxyConfig.port > 0) {
        logger.warn { "Using SOCKS Proxy: ${ProxyConfig.url}:${ProxyConfig.port}" }
        proxy = ProxyBuilder.socks(ProxyConfig.url, ProxyConfig.port)
    }
    

    Clearly validating against null would be cleaner.

    Suggested solutions:

    • Change the default value of default to something other than null, this would require some new type for this and might break compatibility.
    • Introduce a separate set of delegates: OptionalStringSetting, OptionalIntSetting. Ideally, the default value would have to be removed from the current settings so they are always required. But this could also make them more readable.
    opened by Galarzaa90 0
HttpMocker is a simple HTTP mocking library written in Kotlin to quickly and easily handle offline modes in your apps

HttpMocker HttpMocker is a very lightweight Kotlin library that allows to mock HTTP calls relying on either OkHttp or the Ktor client libraries. It ca

David Blanc 174 Nov 28, 2022
Kotlin HTTP requests library. Similar to Python requests.

khttp khttp is a simple library for HTTP requests in Kotlin. It functions similarly to Python's requests module. import khttp.get fun main(args: Arra

Anna Clemens 466 Dec 20, 2022
The easiest HTTP networking library for Kotlin/Android

Fuel The easiest HTTP networking library for Kotlin/Android. You are looking at the documentation for 2.x.y.. If you are looking for the documentation

Kittinun Vantasin 4.3k Jan 8, 2023
An RPC library for Kotlin services that strives to balance developer productivity and performance.

IndieRpc An RPC library for Kotlin services that strives to balance developer productivity and performance. IndieRpc is inspired by Golang's net/rpc p

Asad Awadia 3 Nov 30, 2021
gRPC-Kotlin/JVM - An RPC library and framework

gRPC-Kotlin/JVM - An RPC library and framework A Kotlin/JVM implementation of gRPC: A high performance, open source, general RPC framework that puts m

null 2 Nov 25, 2021
A "fluent" OkHTTP library for Kotlin based on string extensions.

okfluent A "fluent" OkHTTP library for Kotlin based on string extensions. Do not take this project seriously, I just wanted to show that this kind of

Duale Siad 0 Nov 23, 2021
Kotlin-REST-Retrofit - Simple client to consume a REST API with Retrofit using Kotlin

Kotlin REST Retrofit Sencillo cliente para consumir una API REST con Retrofit us

José Luis González Sánchez 5 Nov 4, 2022
Ktorfit - a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Ktorfit is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Jens Klingenberg 637 Dec 25, 2022
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Jan 8, 2023
dns library for android

Qiniu Happy DNS for Android 安装 直接安装 通过maven 使用方法 DnsManager 可以创建一次,一直使用。 IResolver[] resolvers = new IResolver[3]; resolvers[0] = AndroidDnsSe

Qiniu Cloud 270 Dec 5, 2022