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

eclipse

(Mark E. Scott, Jr.) #1

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?


Eclipse bug during import of gradle project (controlsfx-samples)
Eclipse bug during import of gradle project (controlsfx-samples)
(Donát Csikós) #2

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.


(Mark E. Scott, Jr.) #3

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.


(Mark E. Scott, Jr.) #4

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 importing.zip (104.9 KB)

eclipse.buildId=4.5.1.M20150904-0015
java.version=1.8.0_66
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

org.eclipse.buildship.core
Error
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(DefaultWorkspaceOperations.java:159)
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceGradleOperations.addNewEclipseProjectToWorkspace(DefaultWorkspaceGradleOperations.java:222)
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceGradleOperations.synchronizeNonWorkspaceProject(DefaultWorkspaceGradleOperations.java:189)
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceGradleOperations.synchronizeGradleProjectWithWorkspaceProject(DefaultWorkspaceGradleOperations.java:109)
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceGradleOperations.synchronizeGradleBuildWithWorkspace(DefaultWorkspaceGradleOperations.java:70)
at org.eclipse.buildship.core.workspace.SynchronizeGradleProjectJob.runToolingApiJobInWorkspace(SynchronizeGradleProjectJob.java:71)
at org.eclipse.buildship.core.util.progress.ToolingApiWorkspaceJob$1.run(ToolingApiWorkspaceJob.java:74)
at org.eclipse.buildship.core.util.progress.ToolingApiInvoker.invoke(ToolingApiInvoker.java:54)
at org.eclipse.buildship.core.util.progress.ToolingApiWorkspaceJob.runInWorkspace(ToolingApiWorkspaceJob.java:71)
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.IllegalStateException: Workspace already contains a project with name business.
at com.google.common.base.Preconditions.checkState(Preconditions.java:150)
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceOperations.createProject(DefaultWorkspaceOperations.java:132)
… 10 more


(Mark E. Scott, Jr.) #5

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.


(Stefan Oehme) #6

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) {
  eclipse.project.name = (rootProject.name + project.path).replaceAll(':', '-')
}

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


(Gregory Amerson) #7

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)


(Stefan Oehme) #8

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.


(Gregory Amerson) #9

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.


(Khai Dinh) #10

Still working with Eclipse Photon (Release 4.8.0)