Allprojects tasks and a task with that name already exists


(RJ Ewing) #1

I have projectA, projectB, projectC.

projectA and projectB both depend on projectC. projectA includes projectB as well.

I want to be able to run a task on allprojects when I build projectA or when I build projectB, as projectB needs to be able to be built independently of projectA, so I included “allprojects{ task myTask << {} }” in the build.gradle for projectA and projectB.

I get the following error in projectA:

Cannot add task ‘:projectB:myTask’ as a task with that name already exists.


(Benjamin Muschko) #2

If you want to define the task just for a single project, then there’s no need to define it within allprojects. What I’d rather do is to define the logic on in the root project of projectA and projectB e.g.

configure([project(':projectA'), project(':projectB']) {
    task myTask << {}
}

If that doesn’t help, please provide a sample project that reproduces the issue. I’d need to see the hierarchy and the build logic.