https://github.com/limebeck/build-time-config
Gradle plugin for providing build-time configuration properties
https://github.com/limebeck/build-time-config
buildconfig config gradle gradle-kotlin-dsl gradle-plugin kotlin kotlin-dsl kotlin-multiplatform
Last synced: 4 months ago
JSON representation
Gradle plugin for providing build-time configuration properties
- Host: GitHub
- URL: https://github.com/limebeck/build-time-config
- Owner: LimeBeck
- Created: 2023-04-08T19:03:43.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-07T11:29:13.000Z (11 months ago)
- Last Synced: 2025-02-01T23:51:06.146Z (4 months ago)
- Topics: buildconfig, config, gradle, gradle-kotlin-dsl, gradle-plugin, kotlin, kotlin-dsl, kotlin-multiplatform
- Language: Kotlin
- Homepage:
- Size: 94.7 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# Gradle plugin for providing build-time configuration properties

## Usage
There is two API-styles available
1. New-style API (based on delegates)
`build.gradle.kts`:
```kotlin
plugins {
kotlin("jvm") version "2.0.0"
id("dev.limebeck.build-time-config") version "2.3.0"
}
...
buildTimeConfig {
config {
packageName.set("dev.limebeck.config")
objectName.set("MyConfig")
destination.set(project.buildDir)
configProperties {
val someProp: String by string("SomeValue")
val somePropNullable: String? by string(null)
val somePropNullableFilled: String? by string("null")
val someProp2 by number(123)
val someProp3 by number(123.0)
val someProp4 by number(123L)
val someProp5 by bool(true) //also can be boolean(true)
val nested by obj {
val someProp by string("SomeValue")
}
}
}
}
```2. Old-style API (DEPRECATED)
`build.gradle.kts`:
```kotlin
plugins {
kotlin("jvm") version "2.0.0"
id("dev.limebeck.build-time-config") version "2.3.0"
}
...
buildTimeConfig {
config {
packageName.set("dev.limebeck.config")
objectName.set("MyConfig")
destination.set(project.buildDir)
configProperties {
property("someProp") set "SomeValue"
property("someProp2") set 123
property("someProp3") set 123.0
property("someProp4") set 123L
property("someProp5") set true
obj("nested") set {
property("someProp") set "SomeValue"
}
}
}
}
```Both will generate code like this:
```kotlin
package dev.limebeck.configimport kotlin.Boolean
import kotlin.Double
import kotlin.Int
import kotlin.Long
import kotlin.Stringpublic object MyConfigNew {
public val stringProp: String = "SomeValue"public val stringPropNullable: String? = null
public val stringPropNullableFilled: String? = "null"
public val intProp: Int = 123
public val doubleProp: Double = 123.0
public val longProp: Long = 123
public val boolProp: Boolean = true
public val nested: Nested = object : Nested {
override val stringProp: String = "SomeValue"
}public interface Nested {
public val stringProp: String
}
}
```You can use config like this:
`Application.kt`
```kotlin
import dev.limebeck.config.MyConfigclass Application {
val data: String = MyConfig.someProp
val data2: Int = MyConfig.someProp2
val data3: Double = MyConfig.someProp3
val data4: Long = MyConfig.someProp4
val data5: Boolean = MyConfig.someProp5
val obj: String = MyConfig.nested.someProp
}
```Example available in `example/build.gradle.kts` and `example/src/test/kotlin/ConfigurationTest.kt`