Yaml Config Manager
The main entry point for KConfig -- a type-safe, annotation-driven YAML configuration manager for Kotlin.
YamlConfigManager provides a complete lifecycle for managing YAML configuration files backed by Kotlin data classes:
Register custom serializers for types not natively supported.
Register migrations to upgrade configuration schemas across versions.
Load a configuration from a YAML file (creating it with defaults if absent).
Save a configuration back to YAML with comments and proper formatting.
Reload a configuration from disk on demand.
Watch a configuration file for changes and auto-reload.
Full lifecycle example:
// 1. Register custom serializers (optional)
YamlConfigManager.registerSerializer(Duration::class, DurationSerializer)
// 2. Register migrations (optional)
YamlConfigManager.registerMigration(MyConfig::class, MigrateV1ToV2)
// 3. Load configuration
val config = YamlConfigManager.load<MyConfig>(dataFolder.resolve("config.yml"))
// 4. Save configuration
YamlConfigManager.save(dataFolder.resolve("config.yml"), config)
// 5. Reload on demand
val fresh = YamlConfigManager.reload<MyConfig>(dataFolder.resolve("config.yml"))
// 6. Watch for file changes
YamlConfigManager.watch<MyConfig>(dataFolder.resolve("config.yml")) { newConfig ->
println("Config reloaded: $newConfig")
}
// 7. Debug output with secret masking
println(YamlConfigManager.toDebugString(config))
// 8. Cleanup watchers on shutdown
YamlConfigManager.stopAllWatchers()Built-in features:
Automatic default generation from data class constructor defaults
@Commentannotations rendered as YAML comments@Envannotations for environment variable overrides@Secretannotations for masking sensitive values in debug output@Transientannotations for excluding fields from serializationSchema versioning and migration with automatic backups
File watching with debounced auto-reload
Colored error reporting with field-level validation details
Built-in serializers: The manager automatically registers serializers for common types including SecretString. Additional Bukkit serializers are available via club.skidware.kconfig.bukkit.BukkitSerializers.registerAll.
Since
1.0
See also
Properties
The serializer registry used to resolve TypeSerializer implementations for custom types during serialization and deserialization.
Functions
Registers a ConfigMigration for the given configuration type klass.
Registers a custom TypeSerializer for the reified type T.
Registers a custom TypeSerializer for the given type klass.
Sets the output stream used for error and diagnostic messages.
Stops all active file watchers and clears the watcher registry.
Stops watching the specified file for changes.