Skip to content

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 = inputs.files.singleFile.readText().fromJsonSet<com.autonomousapps.advice.ComprehensiveAdvice>()
    println(advice.joinToString("\n"))
  }
}

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:

Advice(dependency=io.reactivex.rxjava2:rxandroid:2.1.0, fromConfiguration=implementation, toConfiguration=null)
Advice(dependency=io.reactivex.rxjava2:rxjava:2.2.9, fromConfiguration=implementation, toConfiguration=api)
Advice(dependency=io.reactivex.rxjava2:rxkotlin:2.3.0, fromConfiguration=implementation, toConfiguration=null)

This is considered the canonical way to consume the produced "advice" at this time.

Clone this wiki locally