Eclipse plugin in multi module build

I have project with some modules that have sub-modules.

If i run gradle clean-eclipse eclipse on a top-module then eclipse for all modules below is updated.

Is there a way to only update the eclipse files in a certain module? I would like to take it slow. One module at the time.

The -p parameter sets the project on which the task should be executed.

gradle -p "modulename" cleanEclipse eclipse

Yes, but it still affects the modules below it. Not just the single one.

does anyone have the answer to my question?

You should be able to do

gradle :foo:cleanEclipse :foo:eclipse

Where “foo” is your module name

This is better but not good enough.

The eclipseProject task is still executes on sub-projects. I would like that no eclipse* tasks are executed on sub-projects.

As a first step, let’s understand the task dependencies so that we can disable them. You can use the Gradle Task Tree Plugin to see the task dependencies


plugins {
    id "com.dorongold.task-tree" version "1.3"

Then run

gradle :foo:cleanEclipse :foo:eclipse taskTree

And copy/paste the output

1 Like

Project Foo has a dependency on Bar.
Also I’m haven the eclipse task depending on cleanEclipse.

D:\workspaces\SomeProject\Foo>gradle :eclipse :taskTree

> Task :taskTree

Root project

+--- :cleanEclipse
|    +--- :cleanEclipseClasspath
|    +--- :cleanEclipseJdt
|    \--- :cleanEclipseProject
+--- :eclipseClasspath
+--- :eclipseJdt
+--- :eclipseProject
\--- :Bar:eclipseProject

It changes the .project file in Bar. Spaces becomes tabs and things are ordered differently.

You could do something like

gradle.taskGraph.whenReady { taskGraph ->
   List<Task> eclipseTasks = taskGraph.allTasks.findAll {'eclipse') }
   if (eclipseTasks) {
      Set<Project> sortedProjects = new TreeSet<>(new ProjectComparator())
      // find the highest level project
      Project topProject = sortedProjects.iterator().next()
      // disable any eclipse tasks that aren't for the top project
      eclipseTasks.findAll { it.project != topProject}*.enabled = false

class ProjectComparator implements Comparator<Project> {
   int compare(Project left, Project right) {
      return left == right ? 0 
         : isParent(left, right) ? -1
         : isParent(right, left) ? 1
   boolean isParent(Project left, Project right) {
      Project current = right
      while (current != null) {
         if (left == current.parent) return true
         current = current.parent
      return false

That is not an acceptable solution.

I think that there should be a flag on the Eclipse plugin that enables/disables modifying eclipse files on sub-projects.

That is not an acceptable solution.

You could move ProjectComparator from build.gradle to buildSrc/src/main/groovy/ProjectComparator.groovy if you want to clean it up a bit :slight_smile: