03/27/2023, 10:55 AM
Hi 👋, I have a kotlin project which has 2 dependencies which have a couple of same gradle tasks. Therefore I end up in
A problem occurred configuring project ':shared'.
> Failed to notify project evaluation listener.
   > Cannot add task 'xxx' as a task with that name already exists.
Can you please tell me how to explicitly exclude/disable a task for a dependency?

Dirk Hoffmann

03/27/2023, 1:29 PM
hmm, not really sure, if I understood your challenge (as for me a dependency is something inside dependencies { implementation("group:artifact:0.5.1") }. but generally, one way to define a new/non-existing task in a build.gradle.kts of a (sub)project via:
val myNewTask = tasks.register("myNewTask") { ... }
and if that task already exists (e.g. a plugin created it or a allprojects { ... } / subprojects { } clause in your rootProject, then you can "add" something to the task with
val myNewTask by tasks.existing { ... }
tasks {
    val myNewTask by existing {
        println("evaluating HERE")
        doLast {
            println("execution HERE")
so no need for disabling ... just use
val myNewTask by existing
(or did I misunderstand where your "dependencies" come from which do define/`register` task 'xxx' ??)


03/27/2023, 2:18 PM
Hi Dirk, nice to meet you here and thanks a lot for your answer. My problem is one from hell probably 😞. Not sure how I get there. 1st the naming dependency was maybe a bit unlucky chosen. What I mean: • I have 2 plugins, Plugin A and Plugin B • both plugins are 3rd party • both of them have 3 gradle tasks which are exact the same Therefore I got the error on a gradle build attempt that 2 plugins try to add tasks with same name. I posted above this message the exception stacktrace
My desperation paired with frustration is also a bit high atm because I have no idea what to do here to fix this. Therefore I am extremly grateful for every tip and proposal which may lead to solve this issue


03/27/2023, 2:24 PM
more of a Gradle question than anything Kotlin-related — you'd have the same issue with duplicate task registrations in any project. see the channel description in #gradle for a link to the Gradle community Slack, or use their other online resources
but in short: you should not have multiple plugins that register the same task. you can extract the common logic out into a third plugin that both of your current plugins apply first.