Class AnalyzeCustomPropertiesTask

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
io.github.timoIpeters.custompropertyanalyzer.AnalyzeCustomPropertiesTask
All Implemented Interfaces:
Comparable<org.gradle.api.Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.TaskInternal, org.gradle.api.Named, org.gradle.api.plugins.ExtensionAware, org.gradle.api.Task, org.gradle.util.Configurable<org.gradle.api.Task>

public class AnalyzeCustomPropertiesTask extends org.gradle.api.DefaultTask
Analyzes a Spring Boot project's Java source files to discover all custom properties defined via @Value and @ConfigurationProperties annotations.

The task scans all .java files in the main source set, extracts property keys and their default values, and writes the results to a JSON report file. Default values are resolved by consulting application.properties, application.yml, or application.yaml in src/main/resources. Additional profile-specific files can be included via getAdditionalPropertiesPattern().

Usage:

   ./gradlew analyzeCustomProperties
   ./gradlew analyzeCustomProperties --verbose
   ./gradlew analyzeCustomProperties --outputFile=my-report.json
   ./gradlew analyzeCustomProperties --additionalPropertiesPattern="application-*.yml"
 
The report is written to build/reports/custom-properties-analysis.json by default.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.gradle.api.Task

    org.gradle.api.Task.Namer
  • Field Summary

    Fields inherited from interface org.gradle.api.Task

    TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Task action that drives the full property analysis.
    Glob pattern for additional property files to include in default value resolution, beyond the baseline application.properties, application.yml, and application.yaml.
    The name of the generated JSON report file.
    org.gradle.api.provider.Provider<org.gradle.api.file.RegularFile>
    The output file to which the JSON property report is written.
    boolean
    Whether to print the full analysis results to the console in addition to the JSON report.
    void
    setAdditionalPropertiesPattern(String additionalPropertiesPattern)
    Option to set an additional properties glob pattern
    void
    setOutputFile(String outputFile)
    Option to set a custom output file
    void
    setVerboseMode(boolean verboseMode)
    Option to enable/disable verbose mode

    Methods inherited from class org.gradle.api.DefaultTask

    compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService

    Methods inherited from class org.gradle.api.internal.AbstractTask

    acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjects

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.gradle.api.Task

    doNotTrackState, getConvention, notCompatibleWithConfigurationCache
  • Constructor Details

    • AnalyzeCustomPropertiesTask

      public AnalyzeCustomPropertiesTask()
  • Method Details

    • getOutputFile

      @Input @Optional public String getOutputFile()
      The name of the generated JSON report file.

      The file is written to build/reports/<outputFile>. Defaults to custom-properties-analysis.json.

      Returns:
      The output file name
    • getAdditionalPropertiesPattern

      @Input @Optional public String getAdditionalPropertiesPattern()
      Glob pattern for additional property files to include in default value resolution, beyond the baseline application.properties, application.yml, and application.yaml.

      Example values:

      • application-dev.properties - exact file name
      • application-dev*.properties - all dev variant files
      • application-*.yml - all profile-specific YAML files
      If not set, only the baseline files are consulted.
      Returns:
      The additional properties glob pattern
    • getVerboseMode

      @Input public boolean getVerboseMode()
      Whether to print the full analysis results to the console in addition to the JSON report. Defaults to false.
      Returns:
      True if verbose mode is enabled, otherwise false
    • setOutputFile

      public void setOutputFile(String outputFile)
      Option to set a custom output file
      Parameters:
      outputFile - The name of the generated JSON report file
    • setAdditionalPropertiesPattern

      public void setAdditionalPropertiesPattern(String additionalPropertiesPattern)
      Option to set an additional properties glob pattern
      Parameters:
      additionalPropertiesPattern - Glob pattern for additional .properties files to include in default value analysis (e.g. 'application-dev*.properties')
    • setVerboseMode

      public void setVerboseMode(boolean verboseMode)
      Option to enable/disable verbose mode
      Parameters:
      verboseMode - Enable verbose console output
    • getReportFile

      @OutputFile public org.gradle.api.provider.Provider<org.gradle.api.file.RegularFile> getReportFile()
      The output file to which the JSON property report is written. Resolved to build/reports/<outputFile>.
      Returns:
      The output file provider, the JSON property is written to
    • analyze

      public void analyze()
      Task action that drives the full property analysis.