autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Task `explodeCodeSourceMain` is not available for lazy configuration

Open
#1,002 1 comment 0 reactions 0 assignees View on GitHub
blocked-by-gradle bug
Dominant language
Kotlin
Stars
2.2k
Forks
158
Avg merge
16h 25m
Merged PRs (30d)
46

Description

**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`

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with `./gradlew buildHealth` and inspect registration of `explodeCodeSourceMain` (`CodeSourceExploderTask`) alongside the `openApiGenerate` task in the affected `api-model` project. Done means the task can be configured with `dependsOn` without `afterEvaluate`, and `buildHealth` no longer reports an undeclared dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.