-
-
Notifications
You must be signed in to change notification settings - Fork 140
Post processing
Tony Robalik edited this page May 27, 2020
·
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
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())
}
}This snippet registers a task in a subproject. This task’s name is "postProcess". One could invoke it
like ./gradlew some-module:postProcess and it would generate output 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.