Problem
The Static Analysis Plugin serves two main purposes:
- A common language to configure and collect results from static analysis tools
- A task (
evaluateViolations
) to execute all those analyses in one go.
The problem is that some projects may be interested in those static analysis tasks separately per tool. For example, to parallelise them in CI pipelines or to defer the execution of the most expensive ones to later build stages.
This was raised here too https://github.com/novoda/gradle-static-analysis-plugin/issues/164
Solution
This is my naive approach to the problem. It creates separate tasks per analysis tool:
evaluateLintViolations
evaluatePMDViolations
evaluateFindbugsViolations
evaluateCheckstyleViolations
evaluateDetektViolations
evaluateKtLintViolations
and makes the original evaluateViolations
task depends on all of them.
The solution Works For Me but it's incomplete existing tests pass, but there are no new ones
If this feature is considered interesting for the project I'm happy to pair to make it better.
Generated tasks
These are the tasks generated for the sample
project inside this repo before and after the change. Notice the new evaluate<TOOL>Violation
tasks.
(Sorry for the hacks to align code blocks side by side on markdown :P)
Before |
After |
Verification tasks
------------------
check
checkstyleAndroidTest
checkstyleAndroidTestDebug
checkstyleDebug
checkstyleMain
checkstyleRelease
checkstyleTest
checkstyleTestDebug
checkstyleTestRelease
collectcheckstyleDebugAndroidTestVariantViolations
collectcheckstyleDebugUnitTestVariantViolations
collectcheckstyleDebugVariantViolations
collectpmdDebugAndroidTestVariantViolations
collectpmdDebugUnitTestVariantViolations
collectpmdDebugVariantViolations
connectedAndroidTest
connectedCheck
connectedDebugAndroidTest
detekt
detektBaseline
detektGenerateConfig
detektIdeaFormat
detektIdeaInspect
deviceAndroidTest
deviceCheck
evaluateViolations
findbugsDebug
findbugsDebugAndroidTest
findbugsDebugUnitTest
ktlintCheck
ktlintDebugCheck
ktlintReleaseCheck
lint
lintDebug
lintRelease
pmdAndroidTest
pmdAndroidTestDebug
pmdDebug
pmdMain
pmdRelease
pmdTest
pmdTestDebug
pmdTestRelease
test
testDebugUnitTest
testReleaseUnitTest
|
.
.
.
.
.
.
Verification tasks
------------------
check
checkstyleAndroidTest
checkstyleAndroidTestDebug
checkstyleDebug
checkstyleMain
checkstyleRelease
checkstyleTest
checkstyleTestDebug
checkstyleTestRelease
collectcheckstyleDebugAndroidTestVariantViolations
collectcheckstyleDebugUnitTestVariantViolations
collectcheckstyleDebugVariantViolations
collectpmdDebugAndroidTestVariantViolations
collectpmdDebugUnitTestVariantViolations
collectpmdDebugVariantViolations
connectedAndroidTest
connectedCheck
connectedDebugAndroidTest
detekt
detektBaseline
detektGenerateConfig
detektIdeaFormat
detektIdeaInspect
deviceAndroidTest
deviceCheck
evaluateCheckstyleViolations
evaluateDetektViolations
evaluateFindbugsViolations
evaluateKtLintViolations
evaluateLintViolations
evaluatePMDViolations
evaluateViolations
findbugsDebug
findbugsDebugAndroidTest
findbugsDebugUnitTest
ktlintCheck
ktlintDebugCheck
ktlintReleaseCheck
lint
lintDebug
lintRelease
pmdAndroidTest
pmdAndroidTestDebug
pmdDebug
pmdMain
pmdRelease
pmdTest
pmdTestDebug
pmdTestRelease
test
testDebugUnitTest
testReleaseUnitTest
|
Now we can execute individual evaluate<TOOL>Violations
tasks separately or the main evaluateViolations
which triggers all the others.
Sample: evaluateCheckstyleViolations
If we choose to execute only an individual task, it runs only its tool analysis and produces only results for itself:
./gradlew evaluateCheckstyleViolations
> Task :app:evaluateCheckstyleViolations
Violations found (1 errors, 0 warnings)
> Checkstyle violations found (1 errors, 0 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/checkstyle/main.html
BUILD SUCCESSFUL in 1s
3 actionable tasks: 2 executed, 1 up-to-date
EvaluateViolations
For existing users changes in this PR are transparent. They'll see individual tasks reporting messages, but the main one will remain exactly the same.
Executing evaluateViolations
with the same project will produce:
./gradlew evaluateViolations
Starting a Gradle Daemon, 1 busy and 1 stopped Daemons could not be reused, use --status for details
> Configure project :app
> Task :app:evaluateCheckstyleViolations
Violations found (1 errors, 0 warnings)
> Checkstyle violations found (1 errors, 0 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/checkstyle/main.html
> Task :app:evaluateDetektViolations
Violations found (0 errors, 26 warnings)
> Detekt violations found (0 errors, 26 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/detekt/detekt.html
> Task :app:evaluateFindbugsViolations
Violations found (0 errors, 2 warnings)
> Findbugs violations found (0 errors, 2 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/findbugs/debug.html
> Task :app:lint
Ran lint on variant release: 1 issues found
Ran lint on variant debug: 1 issues found
Wrote HTML report to file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/lint-results.html
Wrote XML report to file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/lint-results.xml
> Task :app:evaluateLintViolations
Violations found (1 errors, 0 warnings)
> Lint violations found (1 errors, 0 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/lint-results.html
> Task :app:evaluatePMDViolations
Violations found (1 errors, 13 warnings)
> PMD violations found (1 errors, 13 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/pmd/main.html
(...)
> Task :app:evaluatektlintViolations
Violations found (37 errors, 0 warnings)
> ktlint violations found (37 errors, 0 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/ktlint/ktlintMainSourceSetCheck.html
> Task :app:evaluateViolations
Violations found (40 errors, 41 warnings)
> Checkstyle violations found (1 errors, 0 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/checkstyle/main.html
> Detekt violations found (0 errors, 26 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/detekt/detekt.html
> Findbugs violations found (0 errors, 2 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/findbugs/debug.html
> Lint violations found (1 errors, 0 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/lint-results.html
> PMD violations found (1 errors, 13 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/pmd/main.html
> ktlint violations found (37 errors, 0 warnings). See the reports at:
- file:///Users/luisvalle/Developer/workspace/gradle-static-analysis-plugin/sample/app/build/reports/ktlint/ktlintMainSourceSetCheck.html
BUILD SUCCESSFUL in 3s
61 actionable tasks: 15 executed, 46 up-to-date