Why: TaskSelectionException: Task 'testDebug' is ambiguous


I am migrating my multi-modules Android application project from AGP 7.4.2, Gradle 7.6.4, JDK 11 to AGP 8.0.2, Gradle 8.0.2, JDK 17. See this commit.

Before (AGP 7.4.2, Gradle 7.6.4, JDK 11)

Before the referenced commit, I successfully executed tests via:

./gradlew testDebug :engelsystem:test testCcc37C3DebugUnitTest assembleCcc37C3Debug`

After (AGP 8.0.2, Gradle 8.0.2, JDK 17)

Once I checkout the referenced commit and execute the same command it raises the following exception:

org.gradle.execution.TaskSelectionException: Task 'testDebug' is ambiguous in root project 'EventFahrplan' and 
its subprojects. Candidates are: 'testCcc37c3DebugUnitTest', 'testCccamp2023DebugUnitTest', 'testDebugUnitTest', 'testJev2022DebugUnitTest'.

  at org.gradle.execution.DefaultTaskSelector.getSelection(DefaultTaskSelector.java:86)
  at org.gradle.execution.selection.DefaultBuildTaskSelector.resolveTaskName(DefaultBuildTaskSelector.java:98)
  at org.gradle.execution.commandline.CommandLineTaskParser.parseTasks(CommandLineTaskParser.java:49)


The error can be mitigated by executing the following command instead:

./gradlew testDebugUnitTest :engelsystem:test testCcc37C3DebugUnitTest assembleCcc37C3Debug

Question :thinking_face:

Why does testDebug fail all the sudden?
I cannot find any hint in the release notes.


I guess you either are hitting some regression bug, or are hit by a fixed bug.
Even in a virgin 7.6.4 build if I create the tasks it complains for you I get the ambiguous error.
So maybe something in your build is special, so that for some reason you did not get the ambiguous error even though you should have gotten it.

Can you spot what is special about my build? My subjective impression is that the project setup is pretty “boring normal”.

Not without analyzing what is different there, otherwise I would have told.
But if there is a bug, then most probably that it worked before.