Implicit dependency but only when the task is not in the graph

I have a build in which taskB consumes some output from taskA using configuration avoidance friendly mechanisms such that when a build is executed that includes taskB, gradle does not complain about Dealing with validation problems

However if I execute a build which includes just taskA (i.e. taskB is not involved), gradle does complain vocally about Dealing with validation problems

Adding an explicit dependency (i.e. taskB.dependsOn taskA) has no impact, it still complains.

This seems like a bug to me or is there something I’m missing here?

Can you provide the relevant config for taskA and taskB?

I’ve realised that my initial analysis missed some points so I’m no longer 100% sure if it’s a bug or a bad configuration. The fact it only occurs in certain circumstances makes me think bug though but I’ll describe it more fully.

There are 2 plugins applied, one is always applied to the root project and is responsible for aggregating information from 1 or more other projects (which apply the second plugin). It means the two plugins can be applied like

root - pluginA & pluginB

or

root - pluginA
   : child1 - pluginB
   : child2 - pluginB

pluginA includes some configuration which does the following

def consumerTask = project.tasks.register('consumerTask', ConsumerTask, // some config action )
project.allprojects { p ->
    p.pluginManager.withPlugin('pluginB'), {
        consumerTask.configure { ct -> 
            TaskProvider<ProducerTask> producerTask = p.tasks.named('producerTask')
            consumerTask.manifests.add(producerTask.flatMap { it.outputDir.file('some.manifest') })
    }
}

relevant snippet of ConsumerTask is

abstract class ConsumerTask extends DefaultTask {
    @InputFiles
    abstract ListProperty<RegularFile> getManifests() 
}

and for ProducerTask

abstract class ProducerTask extends DefaultTask {
    @OutputDirectory
    abstract DirectoryProperty getOutputDir()
}

However the problem reported comes from another task which is like

abstract class AnotherProducerTask extends DefaultTask {
    @OutputDirectory
    abstract DirectoryProperty getOutputDir()
}

the output directories do overlap

producerTask.outputDir = build/somedir/conf
anotherProducerTask.outputDir = build/somedir

the problem reported is

Execution optimizations have been disabled for task ':anotherProducerTask' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '/projectPath/build/somedir'. Reason: Task ':consumerTask' uses this output of task ':anotherProducerTask' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.1.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.

This problem only occurs in the case where both plugins are applied to the same project, in the multiproject case there is no reported problem.

This difference in behaviour makes me think it is a bug in one way or another. I’ll look at reorganising to avoid the path clash though I’m not sure that is going to be practical