-
-
Notifications
You must be signed in to change notification settings - Fork 140
Post processing
Tony Robalik edited this page Apr 21, 2024
·
9 revisions
For those who want full automation of detecting and fixing issues, you will want to post-process the advice generated by the plugin.
A full-fledged post-processing implementation is out of scope for the moment, but consider the following in order to get started. What follows is an example using Gradle’s runtime API.
some-module/build.gradle.kts
// Create a new task with type `AbstractPostProcessingTask`
val postTask = tasks.register<com.autonomousapps.AbstractPostProcessingTask>("postProcess") {
doLast {
val advice = comprehensiveAdvice()
println(advice.toPrettyString())
}
}
// Get a reference to the extension. Use DependencyAnalysisExtension for the root project.
val dependencyAnalysis =
project.extensions.getByType(com.autonomousapps.DependencyAnalysisSubExtension::class.java)
// Register your new task
dependencyAnalysis.registerPostProcessingTask(postTask)This snippet registers a task in a subproject that will run automatically on an invocation of :buildHealth or :some-module:aggregateAdvice. You could also invoke it manually and it will correctly execute all the depending tasks. The output will look like the following:
{
"dependencyAdvice": [
{
"dependency": {
"identifier": "androidx.appcompat:appcompat",
"resolvedVersion": "1.1.0-rc01",
"configurationName": "implementation"
},
"usedTransitiveDependencies": [],
"fromConfiguration": "implementation"
}
],
"pluginAdvice": [
{
"redundantPlugin": "java-library",
"reason": "this project has both java-library and org.jetbrains.kotlin.jvm applied, which is redundant. You can remove java-library"
}
]
}This is considered the canonical way to consume the produced "advice" at this time.