ConfigLoader

Reads config values from a list of sources. The KSP processor adds a load<Spec>() extension for each @ConfigSpec class, which returns a ConfigResult:

val loader = ConfigLoader {
sources {
+EnvSource()
+TomlSource.fromFile("config.toml")
}
}
val config = loader.loadAppConfig().getOrThrow()

Constructors

Link copied to clipboard
constructor(block: ConfigLoaderBuilder.() -> Unit)

Creates a loader with the sources declared in block's ConfigLoaderBuilder.sources.

Properties

Link copied to clipboard

The sources in priority order: for each field, the first source that has a value wins, and later sources are only asked when earlier ones have none.

Functions

Link copied to clipboard

Runs load and reports, for every field, the value used and which source it came from. Secrets are shown as ***. A value that fails conversion or validation is still listed with its source; the error itself is in ConfigReport.result. Useful for debugging which file or variable won:

Link copied to clipboard

Loads a nullable nested spec under prefix. Returns null, so the field gets its default, when no source has any of the spec's keys; otherwise the spec loads as usual, and missing required keys are errors. Called by generated code.

Link copied to clipboard
fun <T> resolve(field: FieldDescriptor<T>, prefix: String?): ResolveResult<T>

Resolves one field from the sources in priority order. Called by generated code.