Skip to content

Post processing

Tony Robalik edited this page Apr 21, 2024 · 9 revisions

It is possible to register a task that will consume the generated advice, giving sophisticated users full control over the response to issues detected by the plugin.

Note: if you want a way to auto-fix dependency issues reported by the plugin, consider instead simply running the fixDependencies task, or fixDependencies --upgrade for only "safe" fixes.

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 `com.autonomousapps.AbstractPostProcessingTask`
val postTask = tasks.register<AbstractPostProcessingTask>("postProcess") {
  doLast {
    println(projectAdvice())
  }
}

// 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 somewhat like the following (the exact format changes regularly, unfortunately):

{
  "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"
    }
  ]
}
Clone this wiki locally