Fix task inputs to permit caching and up-to-date checks #316
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Our company has a large multi-language gradle project with lots of small sub-projects all of which have associated SonarCloud projects, currently when our developers make any sort of change they follow the normal branch, PR, merge cycle.
I have been tasked with optimising our CI builds but one of the biggest obstacles this amount of time and CPU usage of the analysis steps in our builds, currently all sub-projects are analysed on every build which leads to slow turn around before PRs get the go ahead from the analysis.
We would like that the sonar task would only run when the source files or its dependencies change and that it would use the shared gradle build cache we have. However currently the gradle SonarTask was not implemented in a way that will permit that due to the declared task inputs.
Proposed Changes
Currently
SonarTask.getProperties()
is marked as@Input
which I assume is to satisfy the Gradle API however this contains a lot of computed environment specific values that are tied to the current build agent and working directory. In this PR I have marked this as@Internal
and instead explicitly populate the input object with a filtered version of properties. Additionally I have added aSonarTask.getInputFiles()
method that shall return a list of all the source and library files used in the build so that it will follow the proper gradle update checks on repeated builds.Since this will unexpectedly alter the behaviour of the plugin, I have prevented any caching automatically by adding a new
sonar.gradle.cache
property. Any caching of outputs will be explicitly disabled unless users opt-in