# Eclipse plugin in multi module build

**URL:** https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462
**Category:** Help/Discuss
**Tags:** eclipse, plugins
**Created:** [February 6, 2019, 1:29pm UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462 "2019-02-06T13:29:10Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)
#### Post date: [February 6, 2019, 1:29pm UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/1 "2019-02-06T13:29:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Mehtrick](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mehtrick/32/7465_2.png) [@Mehtrick](https://discuss.gradle.org/u/Mehtrick)
#### Post date: [February 6, 2019, 8:32pm UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/2 "2019-02-06T20:32:49Z")

</div>

> [@kec2](#):
>
> update the eclipse files in a certain module? I would like to take it slow. One

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

```gradle
gradle -p "modulename" cleanEclipse eclipse

```

---

<div class="post-metadata">

### Author: ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)
#### Post date: [February 7, 2019, 6:32am UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/3 "2019-02-07T06:32:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)
#### Post date: [June 18, 2019, 7:38am UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/4 "2019-06-18T07:38:52Z")

</div>

does anyone have the answer to my question?

---

<div class="post-metadata">

### Author: ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)
#### Post date: [June 18, 2019, 10:44am UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/5 "2019-06-18T10:44:26Z")

</div>

You should be able to do

```gradle
gradle :foo:cleanEclipse :foo:eclipse

```

Where “foo” is your module name

---

<div class="post-metadata">

### Author: ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)
#### Post date: [June 20, 2019, 7:25am UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/6 "2019-06-20T07:25:57Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)
#### Post date: [June 20, 2019, 7:47am UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/7 "2019-06-20T07:47:06Z")

</div>

As a first step, let’s understand the task dependencies so that we can disable them. You can use the [Gradle Task Tree Plugin](https://github.com/dorongold/gradle-task-tree) to see the task dependencies

eg:

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

```

Then run

```gradle
gradle :foo:cleanEclipse :foo:eclipse taskTree

```

And copy/paste the output

---

<div class="post-metadata">

### Author: ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)
#### Post date: [June 26, 2019, 8:32am UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/8 "2019-06-26T08:32:39Z")

</div>

> [@Lance](#):
>
> taskTree

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
------------------------------------------------------------

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

```

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

---

<div class="post-metadata">

### Author: ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)
#### Post date: [June 26, 2019, 10:07am UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/9 "2019-06-26T10:07:34Z")

</div>

You could do something like

```gradle
gradle.taskGraph.whenReady { taskGraph ->
   List<Task> eclipseTasks = taskGraph.allTasks.findAll { it.name.toLowerCase().contains('eclipse') }
   if (eclipseTasks) {
      Set<Project> sortedProjects = new TreeSet<>(new ProjectComparator())
      sortedProjects.addAll(eclipseTasks*.project)
      // 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
         : left.name.compareTo(right.name)
      }
   }
   boolean isParent(Project left, Project right) {
      Project current = right
      while (current != null) {
         if (left == current.parent) return true
         current = current.parent
      }
      return false
   }
}

```

---

<div class="post-metadata">

### Author: ![kec2](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@kec2](https://discuss.gradle.org/u/kec2)
#### Post date: [June 27, 2019, 8:09am UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/10 "2019-06-27T08:09:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)
#### Post date: [June 27, 2019, 8:32pm UTC](https://discuss.gradle.org/t/eclipse-plugin-in-multi-module-build/30462/11 "2019-06-27T20:32:05Z")

</div>

> 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 🙂
