autonomousapps / dependency-analysis-gradle-plugin

Gradle plugin for JVM projects written in Java, Kotlin, Groovy, or Scala; and Android projects written in Java or Kotlin. Provides advice for managing dependencies and other applied plugins
Apache License 2.0
1.79k stars 117 forks source link

Outdated documentation for AbstractPostProcessingTask #850

Closed fmatosqg closed 6 months ago

fmatosqg commented 1 year ago

Plugin version 1.18.0

Describe the bug Documentation outdated on how to make a custom post processor task.

To Reproduce Follow snippet found on https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/wiki/Post-processing

Steps to reproduce the behavior:

On root build.gradle.kts add

val postTask = tasks.register<com.autonomousapps.AbstractPostProcessingTask>("postProcess") {
  doLast {
    val advice = comprehensiveAdvice()
    println(advice.toPrettyString())
  }
}

Expected behavior Gradle task to finish, or at least to run the task

Actual behavior

> Task :postProcess FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':postProcess' (type 'AbstractPostProcessingTask').
  - In plugin 'com.autonomousapps.dependency-analysis' type 'com.autonomousapps.AbstractPostProcessingTask' property 'input' doesn't have a configured value.

    Reason: This property isn't marked as optional and no value has been configured.

    Possible solutions:
      1. Assign a value to 'input'.
      2. Mark property 'input' as optional.

Fix proposed

(1) Specifying

// Create a new task with type `AbstractPostProcessingTask`
val postTask = tasks.register<com.autonomousapps.AbstractPostProcessingTask>("postProcess") {
    input.set(File("./build/reports/dependency-analysis/build-health-report.json"))

    doLast {

    val advice = projectAdvice().dependencyAdvice
    println(advice.toPrettyString())
  }
}

(2) Remove any mentions of aggregateAdvice. Is there any task now that is similar?

(3)

Replace documentation from

project.extensions.getByType(com.autonomousapps.DependencyAnalysisSubExtension::class.java)

to

val dependencyAnalysis =
    project.extensions.getByType(com.autonomousapps.DependencyAnalysisExtension::class.java)

This last change is uncertain, since doing it doesn't make the task run with ./gradlew module:projectHealth, and not doing it issues the following error:


* What went wrong:
Extension of type 'DependencyAnalysisSubExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension, BuildScanExtension, GradleEnterpriseExtension, CiMetricsExtension, DependencyAnalysisExtension, ReportingExtension, DetektExtension, JacocoPluginExtension, KtlintExtension]
autonomousapps commented 1 year ago

Thanks for the report.

autonomousapps commented 6 months ago

This test still passes. The spec generates a build.gradle file that contains this bit:

// buildSrc
import com.autonomousapps.AbstractPostProcessingTask;
import org.gradle.api.tasks.TaskAction;

public abstract class PostTask extends AbstractPostProcessingTask {
  @TaskAction public void action() {
    System.out.println(projectAdvice());
  }
}
// project/build.gradle
def postProcess = tasks.register("postProcess", PostTask)
dependencyAnalysis.registerPostProcessingTask(postProcess)

Without a reproducer, I will be unable to explain why you saw a build error about input being misconfigured. Still, I am updating the wiki now to reflect the current state of post-processing. Thanks!