-
-
Notifications
You must be signed in to change notification settings - Fork 140
Post processing
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.
// 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.
The docs below are from the original method of post-processing and will be removed once we’re certain the new approach works well.
tasks.register("postProcess") {
// Get a reference to the extension. Use DependencyAnalysisExtension for the root project.
val dependencyAnalysis =
project.extensions.getByType(com.autonomousapps.DependencyAnalysisSubExtension::class.java)
inputs.file(dependencyAnalysis.adviceOutput())
.withPropertyName("path")
.withPathSensitivity(PathSensitivity.NONE)
doLast {
// Use your preferred json deserialization library. This project uses Moshi. See
// com.autonomousapps.internal.utils.moshi.kt for examples.
val advice: com.autonomousapps.advice.ComprehensiveAdvice =
inputs.files.singleFile.readText().fromJson<com.autonomousapps.advice.ComprehensiveAdvice>()
println(advice.toPrettyString())
}
}