Interface ProjectPropertiesHelper


public interface ProjectPropertiesHelper

This interface provides utility methods to help with loading, merging, and checking project properties in a Gradle project. It supports recursively loading properties files, merging the properties into the project, and verifying the existence of expected properties.

It includes methods for:

  • Recursively loading .properties files from specified directories
  • Checking if a file is a valid .properties file
  • Loading properties from a file
  • Merging the loaded properties into a Gradle project, with the option to override existing properties
  • Checking whether all expected property keys exist in the project
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static void
    checkExpectedKey(@NotNull org.gradle.api.Project project, @NotNull List<String> expectedKeyList)
    Checks whether all expected property keys exist in the Gradle project.
    static boolean
    isPropertiesFile(@NotNull File file)
    Checks if the given file is a valid .properties file based on its name and extension.
    static void
    mergePropertiesTo(@NotNull org.gradle.api.Project project, @NotNull Properties properties, boolean canOverride)
    Merges the provided properties into the Gradle project.
    static void
    recursiveLoadProperties(@NotNull org.gradle.api.Project project, boolean canOverride, @NotNull List<File> files)
    Recursively loads properties files from the specified list of files and directories.
    static @NotNull Properties
    tryLoadPropertiesFile(@NotNull File file)
    Attempts to load a .properties file from the given path.
  • Method Details

    • recursiveLoadProperties

      static void recursiveLoadProperties(@NotNull @NotNull org.gradle.api.Project project, boolean canOverride, @NotNull @NotNull List<File> files)

      Recursively loads properties files from the specified list of files and directories. If a directory is encountered, it will be explored further to find additional properties files. The properties are then merged into the Gradle project.

      Parameters:
      project - the Gradle project to load properties into.
      canOverride - specifies whether existing project properties can be overridden.
      files - a list of files and directories to explore for properties files.
    • isPropertiesFile

      static boolean isPropertiesFile(@NotNull @NotNull File file)

      Checks if the given file is a valid .properties file based on its name and extension.

      Parameters:
      file - the file to check.
      Returns:
      true if the file is a valid .properties file, false otherwise.
    • tryLoadPropertiesFile

      @NotNull static @NotNull Properties tryLoadPropertiesFile(@NotNull @NotNull File file)

      Attempts to load a .properties file from the given path. If the file is valid and can be loaded, the properties will be returned. Otherwise, an empty properties object is returned.

      Parameters:
      file - the file to load properties from.
      Returns:
      a Properties object containing the loaded properties.
    • mergePropertiesTo

      static void mergePropertiesTo(@NotNull @NotNull org.gradle.api.Project project, @NotNull @NotNull Properties properties, boolean canOverride)

      Merges the provided properties into the Gradle project. If a property already exists, it will be overwritten only if canOverride is true. Otherwise, it will not be overridden. New properties will be added to the project.

      Parameters:
      project - the Gradle project to merge properties into.
      properties - the properties to merge into the project.
      canOverride - specifies whether existing properties can be overridden.
    • checkExpectedKey

      static void checkExpectedKey(@NotNull @NotNull org.gradle.api.Project project, @NotNull @NotNull List<String> expectedKeyList) throws org.gradle.api.GradleException

      Checks whether all expected property keys exist in the Gradle project. If any keys are missing, an exception will be thrown, and a list of the missing keys will be logged.

      Parameters:
      project - the Gradle project to check.
      expectedKeyList - the list of expected property keys.
      Throws:
      org.gradle.api.GradleException - if any expected property keys are missing.