Skip to content

@OutputDirectory on projectDirectory breaks running createModuleGraph alongside other tasks #72

Description

@MattSkala

Problem

CreateModuleGraphTask declares projectDirectory as @get:OutputDirectory, and the plugin sets it to the root project directory:

This tells Gradle the task owns the entire project tree as an output. Every other task's outputs (all build/ directories) then sit inside createModuleGraph's declared output, so Gradle's dependency validation fails the build whenever createModuleGraph runs in the same invocation as any other task:

Some problems were found with the configuration of task ':shared:fitify:plans:testAndroidHostTest' (type 'AndroidUnitTest').
Property has implicit dependency
  Gradle detected a problem with the following location: '<repo>/shared/fitify/plans/build/classes/kotlin/android/hostTest'
    Task ':shared:fitify:plans:testAndroidHostTest' uses this output of task ':createModuleGraph' without declaring an
    explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the
    tasks are executed

One such failure is reported per overlapping output location, which on a large project means hundreds of them.

Reproduction

On any multi-module project applying the plugin:

./gradlew test createModuleGraph

Fails with the validation errors above. Running createModuleGraph on its own works.

Root cause

The task only uses projectDirectory to resolve the relative readmePath of each graph config (CreateModuleGraphTask.kt#L154-L155). It is a base directory for path resolution, not an output. The task's real outputs are the readme files it writes.

Suggested fix

Mark projectDirectory as @get:Internal and declare the actual outputs instead, e.g. an @OutputFiles provider that maps each graph config's readmePath resolved against projectDirectory. That keeps up-to-date checks and configuration-cache support while removing the overlap with every other task's outputs.

Workaround

Run createModuleGraph in its own Gradle invocation, separate from other tasks.

Environment

  • module-graph 0.13.0
  • Gradle 9.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions