Eclipse Workspace Plugin

If you have a physical nested multi-project build as it is often the case with an ear project, and you apply the eclipse plugin to each project, it generates the necessary metadata just fine. But if you want to add them to eclipse then you need to import each project separately by hand since eclipse will not scan subfolders for subprojects if it has found a project in the root folder.

The only thing the workspace plugin should be doing is to either create a new workspace that just has those projects all added, or add them to an existing workspace.

I’ve already looked into it a bit and it seems that this will be not as easy as placing some textfiles in the right folders, since eclipse uses some binary storage format for its workspace metadata.

I’ve found some code on how to add the Project to the Workspace via code, but this will require some eclipse dependencies and an osgi container.

String theProjName = "Test";
String theLocation = "/some/test/project";
  try {
    IWorkspaceRoot theRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject theProject = theRoot.getProject(theProjName);
    IProjectDescription theDesc =
        theDesc.setLocation(new Path(theLocation));
    theProject.create(theDesc, new NullProgressMonitor());
    if (theProject.exists()) { NullProgressMonitor());
} catch (CoreException err) {

Is there anyone interested in this and would like to help with coding or other ideas?

Have you tried using the STS Gradle plugin? This is a plugin that runs in Eclipse to import and run Gradle builds. It deals with the import problem, in that you just point it at the root project and it offers to import all the subprojects into the workspace.

Not yet, I’ve always used a plain J2EE Eclipse for my projects and run gradle as external tool. Going to check it out.

I had the same problem and found help on the gradle-users mailing list that came up with this solution, which is to add this to your project’s root build.gradle file –

// This is a cool example of the power of gradle.
Eclipse can't handle hierarchal projects.
// so this is a clever way to use gradle to filter out which projects we want to apply the eclipse
// plugin too. Suggestion comes from
  def leafProjects = subprojects.findAll {
     it.childProjects.size() == 0
   configure(leafProjects) {
     apply plugin: 'eclipse'

With this, only the leaf projects of your multi-project builds will get eclipse project meta-data generated.

It is quite quirky, for some reason it tried to use Milestone-4 and it couldn’t deal with custom plugins I had to remove them before I could import the project. Furthermore the project had to be outside the actual workspace or you get the error that a project already exists at the location.

I need to retract my statement about the custom plugin there was an error in the build.gradle that caused issues when it was applied. But the other problems remain. “H:\Workspaces\STS\test overlaps the location of another project: ‘test’”