Class KissConfigBuilder

java.lang.Object
io.github.arthurhoch.kissconfig.KissConfigBuilder

public final class KissConfigBuilder extends Object
Builder for explicit KissConfig loading.

Defaults are application.properties, no env file, no profile, SearchOrder.defaults(), and MergeStrategy.FILL_MISSING_ONLY. Env files are opt-in through envFile(String), envFile(Path), or an explicit ConfigLocation.envFile(String) in the configured search order. See docs/search-order.md, docs/profiles.md, and docs/env-files.md for detailed behavior.

  • Method Details

    • propertyFile

      public KissConfigBuilder propertyFile(String propertyFile)
      Sets the property file name or path used by compatible locations.

      With an active profile, directory and classpath locations also attempt a profile variant such as application-prod.properties for profile prod.

      Parameters:
      propertyFile - property file
      Returns:
      this builder
    • propertyFile

      public KissConfigBuilder propertyFile(Path propertyFile)
      Sets the property file name or path used by compatible locations.

      With an active profile, directory and classpath locations also attempt a profile variant such as application-prod.properties for profile prod.

      Parameters:
      propertyFile - property file
      Returns:
      this builder
    • envFile

      public KissConfigBuilder envFile(String envFile)
      Configures env file loading.

      Env files are not loaded by default. When this method is used, directory-based locations attempt the configured env file and, when a profile is active, a profile variant. For .env and profile prod, the profile variant is .env.prod.

      Parameters:
      envFile - env file
      Returns:
      this builder
    • envFile

      public KissConfigBuilder envFile(Path envFile)
      Configures env file loading.

      Env files are not loaded by default. When this method is used, directory-based locations attempt the configured env file and, when a profile is active, a profile variant. For myapp.env and profile prod, the profile variant is myapp-prod.env.

      Parameters:
      envFile - env file
      Returns:
      this builder
    • profile

      public KissConfigBuilder profile(String profile)
      Sets the active profile.

      Profiles are validated against [a-zA-Z0-9_-]+. Profiles are not enabled automatically by SearchOrder.production().

      Parameters:
      profile - profile name matching [a-zA-Z0-9_-]+
      Returns:
      this builder
    • searchOrder

      public KissConfigBuilder searchOrder(SearchOrder searchOrder)
      Sets the source search order.

      SearchOrder is read order. Priority depends on the active MergeStrategy.

      Parameters:
      searchOrder - search order
      Returns:
      this builder
    • mergeStrategy

      public KissConfigBuilder mergeStrategy(MergeStrategy mergeStrategy)
      Sets the merge strategy.

      The default is MergeStrategy.FILL_MISSING_ONLY. Override and duplicate-fail behavior must be selected explicitly.

      Parameters:
      mergeStrategy - merge strategy
      Returns:
      this builder
    • ignoreMissingExplicitFiles

      public KissConfigBuilder ignoreMissingExplicitFiles(boolean ignoreMissingExplicitFiles)
      Controls missing explicit file behavior.

      Auto-discovered missing files are skipped. Explicit files declared through ConfigLocation.file(String) or ConfigLocation.envFile(String) fail when missing unless this is set to true.

      Parameters:
      ignoreMissingExplicitFiles - true to skip missing explicit files
      Returns:
      this builder
    • mapTo

      public <T> T mapTo(Class<T> targetType)
      Loads and maps configuration to the target record type, returning only the mapped value.
      Type Parameters:
      T - target type
      Parameters:
      targetType - target type
      Returns:
      mapped configuration object
    • load

      public <T> KissConfigResult<T> load(Class<T> targetType)
      Loads and maps configuration to the target record type, returning value, sources, map, and report.
      Type Parameters:
      T - target type
      Parameters:
      targetType - target type
      Returns:
      load result