Error while using Gradle Buildship nature in a custom Eclipse plugin

I have already developed a similar plugin myself. I assume your plugin:

  1. Generates a Gradle build (settings.gradle, build.gradle, …) or checks out an existing project from source control (e.g. Git)
  2. Imports this build into the Eclipse Workspace with Eclipse Buildship

In step 1 no .classpath or .project files and no .settings folders should be written. These are automatically added in step 2 by Buildship.

A very basic handler for importing a Gradle build could look like this:

public class ImportHandler extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        Job job = new Job("Import") {
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                File rootDir = new File("/home/ole/data/workspace/demo");
                BuildConfigurationBuilder builder = BuildConfiguration.forRootProjectDirectory(rootDir);
                GradleBuild build = GradleCore.getWorkspace().createBuild(builder.build());
                build.synchronize(monitor);
                return Status.OK_STATUS;
            }
        };
        job.schedule();
        return null;
    }

}

To narrow down errors you should look at these places:

  1. Gradle Operations Console (in the Console View)
  2. Error Log (Window > Show View > Error Log)
  3. When you are running/debugging your plugin from a launch configuration: Console for the running Eclipse Application

The Javadoc for GradleBuild from org.eclipse.buildship.core is also a good starting point.

To help you further, you should share a minimal example that demonstrates your problem.

1 Like