dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

Task `explodeCodeSourceMain` is not available for lazy configuration

Open madorb opened this issue 2 years ago • 1 comments
trafficstars

Plugin version 1.25.0

Gradle version 8.4

JDK version openjdk 17.0.8.1 2023-08-24

(Optional) Android Gradle Plugin (AGP) version Not android

Describe the bug I have a multi-module project, that has a module api-model that generates source code (model classes) from an OpenApi specification. When i add com.autonomousapps.dependency-analysis to the root module and run ./gradlew buildHealth i get the following:

* What went wrong:
A problem was found with the configuration of task ':api-model:explodeCodeSourceMain' (type 'CodeSourceExploderTask').
  - Gradle detected a problem with the following location: '/my-project/lib/api-model/build/src/main/generated'.

    Reason: Task ':api-model:explodeCodeSourceMain' uses this output of task ':api-model:openApiGenerate' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':api-model:openApiGenerate' as an input of ':api-model:explodeCodeSourceMain'.
      2. Declare an explicit dependency on ':api-model:openApiGenerate' from ':api-model:explodeCodeSourceMain' using Task#dependsOn.
      3. Declare an explicit dependency on ':api-model:openApiGenerate' from ':api-model:explodeCodeSourceMain' using Task#mustRunAfter.

running ./gradlew :api-model:tasks i see that there is a task called explodeCodeSourceMain:

Dependency-analysis-internal tasks
----------------------------------
artifactsReportMain - Produces a report that lists all direct and transitive dependencies, along with their artifacts
...
explodeCodeSourceMain - Parses Java and Kotlin source to detect source-only usages
explodeCodeSourceTest - Parses Java and Kotlin source to detect source-only usages
...
OpenAPI Tools tasks
-------------------
openApiGenerate - Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents.
...

Unfortunately though, when i follow the above advice and add:

    tasks.named("explodeCodeSourceMain") {
        dependsOn(project.tasks.named("openApiGenerate"))
    }

I receive:

* What went wrong:
Task with name 'explodeCodeSourceMain' not found in project ':api-model'.

It looks like i can work around this with an afterEvaluate... but is there a better solution to make sure that the explodeCodeSourceMain task lazily available for configuration?

afterEvaluate {
    tasks.named("explodeCodeSourceMain") {
        dependsOn(project.tasks.named("openApiGenerate"))
    }
}

To Reproduce Apply the org.openapi.generator plugin to the api-model module as well as com.autonomousapps.dependency-analysis to the parent module.

Expected behavior Adding a dependsOn for explodeCodeSourceMain should not require an afterEvaluate

madorb avatar Oct 24 '23 15:10 madorb

I believe this is essentially a duplicate of https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/685, which is the result of a Gradle issue not properly wiring in task dependencies when generating tasks contribute to a source set. For now, I would suggest this workaround.

Here's the Gradle issue https://github.com/gradle/gradle/issues/25885

autonomousapps avatar Nov 02 '23 03:11 autonomousapps