Skip to content

rocketraman/cfg4k

 
 

Repository files navigation

Build Status Coverage Status License Download

News

Like the original author, I'm not actively maintaining cfg4k any longer. I've migrated to using Hoplite which, with some PRs from me, bring it to functional equivalency or better with cfg4k.

Overview

Cfg4k is a configuration library made for Kotlin in Kotlin!

Features

  • Automatic reload
  • Interface binding
  • Ability to handle data classes automatically
  • All the complex types and generics are supported
  • Huge flexibility, custom sources
  • Easy to use
  • Bytebuddy provider will be able to compile your bindings at runtime (You will need to add the cfg4k-bytebuddy to your dependencies.)

For further information, use the wiki

Quick start

  1. Add the Bintray repository:
repositories {
    jcenter()
}
  1. Add the dependency for the module(s) that you are going to use
implementation 'com.jdiazcano.cfg4k:cfg4k-core:$VERSION'
fun main(args: Array<String>) {
    val source = ClassPathConfigSource("global.properties")         // Create source
    val loader = PropertyConfigLoader(source)                       // Create loader
    val provider = ProxyConfigProvider(loader)                      // Create provider
    val databaseConfig = provider.bind<DatabaseConfig>("database")  // bind and use

    println("Name: ${databaseConfig.name()}")
    println("Url: ${databaseConfig.url()}")
    println("Port: ${databaseConfig.port()}")
}

/**
 * This interface defines a database configuration
 */
interface DatabaseConfig {
    /**
     * You can have javadocs inside your properties and this is really cool
     */
    fun url(): String
    fun port(): Int
    fun name(): String

    // if you have an unused property you know it and you can delete it
    val unused: String

    @Deprecated("You can even deprecate properties!")
    fun deprecated(): Boolean
    
    val youCanuseValuesToo: String
    val andNullables: Int?
}

Architeture overview

Lightbox

License

Licensed under the Apache License, Version 2.0. See LICENSE file.

About

Flexible and easy to use config library written in kotlin

Resources

License

Stars

Watchers

Forks

Languages

  • Kotlin 100.0%