Class CheckUnusedPropertiesTask
- 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>
This task reads the report produced by analyzeCustomProperties to obtain the
set of all properties referenced in code, then compares it against the keys found in
application.properties, application.yml, or application.yaml
(+ additional files based on a glob pattern).
Any key present in a configuration file but absent from the code is flagged as unused.
By default, the build fails if unused properties are found, making this task
suitable as a CI gate. Pass --ignoreUnused to report without failing.
This task depends on analyzeCustomProperties and runs it automatically.
Usage:
./gradlew checkUnusedProperties ./gradlew checkUnusedProperties --verbose ./gradlew checkUnusedProperties --outputFile=my-unused-report.json ./gradlew checkUnusedProperties --ignoreUnused ./gradlew checkUnusedProperties --additionalPropertiesPattern="application-*.yml"The report is written to
build/reports/unused-properties-report.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 -
Method Summary
Modifier and TypeMethodDescriptionvoidcheck()Task action that compares defined configuration keys against code-referenced keys and flags any that are unused.Glob pattern for additional property files to include when scanning for unused keys, beyond the baselineapplication.properties,application.yml, andapplication.yaml.The name of the analysis report file produced byanalyzeCustomPropertiesto read referenced property keys from.org.gradle.api.provider.Provider<org.gradle.api.file.RegularFile>The analysis report file produced byanalyzeCustomProperties, used as input to determine which property keys are referenced in code.booleanWhether to suppress build failure when unused properties are found.The name of the generated JSON report file listing unused properties.org.gradle.api.provider.Provider<org.gradle.api.file.RegularFile>The output file to which the unused properties JSON report is written.booleanWhether to print the full unused properties results to the console in addition to the JSON report.voidsetAdditionalPropertiesPattern(String additionalPropertiesPattern) Option to set an additional properties glob patternvoidsetAnalysisReportFile(String analysisReportFile) Option to set a custom analysis report file namevoidsetIgnoreUnused(boolean ignoreUnused) Option to enable/disable build failure when unused properties are detectedvoidsetOutputFile(String outputFile) Option to set a custom output file namevoidsetVerboseMode(boolean verboseMode) Option to enable/disable verbose console outputsMethods 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, usesServiceMethods 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, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, getConvention, notCompatibleWithConfigurationCache
-
Constructor Details
-
CheckUnusedPropertiesTask
public CheckUnusedPropertiesTask()
-
-
Method Details
-
getAnalysisReportFile
The name of the analysis report file produced byanalyzeCustomPropertiesto read referenced property keys from. Defaults tocustom-properties-analysis.json.- Returns:
- The analysis report file name
-
getOutputFile
The name of the generated JSON report file listing unused properties.The file is written to
build/reports/<outputFile>. Defaults tounused-properties-report.json.- Returns:
- The unused properties output file name
-
getAdditionalPropertiesPattern
Glob pattern for additional property files to include when scanning for unused keys, beyond the baselineapplication.properties,application.yml, andapplication.yaml.Use this to include profile-specific files such as
application-prod.ymlin the unused property check. This option is independent of the same option onanalyzeCustomProperties— set it based on which files you want to audit for orphaned keys.- Returns:
- The additional properties glob pattern
-
getIgnoreUnused
@Input public boolean getIgnoreUnused()Whether to suppress build failure when unused properties are found.When
false(the default), the build fails if any unused properties are detected. Whentrue, unused properties are reported in the JSON output and console but the build continues.- Returns:
- True if ignore unused flag is set, otherwise false
-
getVerboseMode
@Input public boolean getVerboseMode()Whether to print the full unused properties results to the console in addition to the JSON report. Defaults tofalse.- Returns:
- True if verbose mode is enabled, otherwise false
-
setAnalysisReportFile
Option to set a custom analysis report file name- Parameters:
analysisReportFile- Name of the analysis report produced by analyzeCustomProperties. Default: custom-properties-analysis.json
-
setOutputFile
Option to set a custom output file name- Parameters:
outputFile- Name of the generated unused-properties report file. Default: unused-properties-report.json
-
setAdditionalPropertiesPattern
Option to set an additional properties glob pattern- Parameters:
additionalPropertiesPattern- Glob pattern for additional property files to include (e.g. 'application-*.yml'). Should match what was passed to analyzeCustomProperties.
-
setIgnoreUnused
public void setIgnoreUnused(boolean ignoreUnused) Option to enable/disable build failure when unused properties are detected- Parameters:
ignoreUnused- If set, unused properties are reported but the build does not fail.
-
setVerboseMode
public void setVerboseMode(boolean verboseMode) Option to enable/disable verbose console outputs- Parameters:
verboseMode- Enable verbose console output.
-
getAnalysisReportFileProvider
@InputFile public org.gradle.api.provider.Provider<org.gradle.api.file.RegularFile> getAnalysisReportFileProvider()The analysis report file produced byanalyzeCustomProperties, used as input to determine which property keys are referenced in code. Resolved tobuild/reports/<analysisReportFile>.- Returns:
- The analysis report file provider
-
getReportFile
@OutputFile public org.gradle.api.provider.Provider<org.gradle.api.file.RegularFile> getReportFile()The output file to which the unused properties JSON report is written. Resolved tobuild/reports/<outputFile>.- Returns:
- The report file provider
-
check
public void check()Task action that compares defined configuration keys against code-referenced keys and flags any that are unused.
-