Multiple gradle projects imported into the same workspace, conflicts with hierarchy

In our case, we have noticed since going to a hierarchical gradle project setup (:business:foo:bar, :business:test:123), the implicit project for :business can conflict fairly easily.

For instance, if we import two gradle root projects into the workspace, and both contain projects in the :business hierarchy, eclipse fails with “Cannot create Eclipse project business” - “Workspace already contains a project with name business”. There may not be explicit projects with the same name, but the implicit ones created by Gradle for the nodes sure can be easy to duplicate.

Is there something we are doing wrong here, or is it a current limitation?

Unfortunately it is a limitation now: Buildship expects that none of the project names are taken in the workspace. Consequently, if you try to import two separate builds containing overlapping module names, the second one will fail. If you are interested you can subscribe to the related Bugzilla issue. Please note though it is only planned but not scheduled for the time being.

Thanks, I added comments to it that enforce the understanding this affects implicit hierarchical projects, even if you have no leaf projects with the same name.

To possibly help expedite this when it gets attention, I have created a bare bones directory tree that exhibits the behavior described. This zip file contains two Gradle root projects, with exactly 1 project loaded each.

I can load “Gradle Root Project A” just fine, but when I go to import “Gradle Root Project B”, I get the error listed at the bottom of this post.

Now that v1.0.6 has been released (and the 1.0.7 snapshot), I am no longer using a snapshot version of 1.0.6. Version details are provided below as well from my last test.

buildship bug (104.9 KB)

java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product org.eclipse.epp.package.jee.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product

Thu Dec 10 13:03:25 CST 2015
Synchronize Gradle root project at C:\tmp\buildship bug importing\buildship bug importing\Gradle Root Project B with workspace failed due to an error configuring Eclipse.

org.eclipse.buildship.core.GradlePluginsRuntimeException: Cannot create Eclipse project business.
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceOperations.createProject(
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceGradleOperations.addNewEclipseProjectToWorkspace(
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceGradleOperations.synchronizeNonWorkspaceProject(
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceGradleOperations.synchronizeGradleProjectWithWorkspaceProject(
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceGradleOperations.synchronizeGradleBuildWithWorkspace(
at org.eclipse.buildship.core.workspace.SynchronizeGradleProjectJob.runToolingApiJobInWorkspace(
at org.eclipse.buildship.core.util.progress.ToolingApiWorkspaceJob$
at org.eclipse.buildship.core.util.progress.ToolingApiInvoker.invoke(
at org.eclipse.buildship.core.util.progress.ToolingApiWorkspaceJob.runInWorkspace(
Caused by: java.lang.IllegalStateException: Workspace already contains a project with name business.
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceOperations.createProject(
… 10 more

Forgot to mention, this is still present with Gradle 2.9. I notice that on importing larger projects, they are named like ‘business-projectA’.

My guess is that when the implicit projects (business) are imported, they aren’t being created with unique names, like is done for the actual leaf projects.

This will be fixed by the composite build feature in Buildship 1.1

In the meantime you can use this in your build script or init script:

if (project != rootProject) { = ( + project.path).replaceAll(':', '-')

This will give you long, unlikely-to-clash project names in Eclipse.

Hey @st_oehme does the above script still work in latest buildship 2.1.x? I’m trying this here in 2017 and it doesn’t seem to be working (but I could be doing it wrong, but just wanted to double check)

Yep, that should work just fine. If you got a scenario where it doesn’t, please open an issue with an example attached and we’ll get it fixed.

Thanks for the reply. If I still can’t get it to work, I’ll build a SSCCE and share it with you on github issue.

Still working with Eclipse Photon (Release 4.8.0)