# How does Buildship create the .classpath file for Eclipse?

**URL:** <https://discuss.gradle.org/t/how-does-buildship-create-the-classpath-file-for-eclipse/26252>\
**Category:** Buildship\
**Tags:** buildship, eclipse\
**Created:** [March 14, 2018, 9:33pm UTC](https://discuss.gradle.org/t/how-does-buildship-create-the-classpath-file-for-eclipse/26252 "2018-03-14T21:33:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert7k](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@robert7k](https://discuss.gradle.org/u/robert7k)\
**Post date:** [March 14, 2018, 9:33pm UTC](https://discuss.gradle.org/t/how-does-buildship-create-the-classpath-file-for-eclipse/26252/1 "2018-03-14T21:33:40Z")

</div>

I’m using Buildship and Gradle with Eclipse. I have [an issue I described on Stackoverflow](https://stackoverflow.com/questions/49068870), but I haven’t found a solution so far, so I’m asking here.

I’m wondering how Buildship creates the `.classpath` file for Eclipse, because apparently the Gradle task `eclipseClasspath` is never executed, but the `.classpath` file gets modified. In the end, I need to modify the order Buildship writes the classpath entries into `.classpath`, so I’m wondering how to do that. Is there a way to convince Buildship to use the Gradle task, or is there some other way to modify the behaviour?

Thank you and best regards,

Robert

---

<div class="post-metadata">

**Author:** ![donat](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/donat/32/7798_2.png) [@donat](https://discuss.gradle.org/u/donat)\
**Post date:** [March 16, 2018, 4:13pm UTC](https://discuss.gradle.org/t/how-does-buildship-create-the-classpath-file-for-eclipse/26252/2 "2018-03-16T16:13:46Z")

</div>

Your observation is correct, Buildship doesn’t call `eclipseClasspath` directly. It reads the configuration from the `java` and the `eclipse` Gradle plugins via the Gradle Tooling API and sets the values by using Eclipse JDT’s API. You can customize the content of the `.classpath` file via the `eclipse.classpath.file.whenMerged` block. You’ll find examples how to that in the [Buildship 1.0.18 release announcement](https://discuss.gradle.org/t/buildship-1-0-18-is-now-available/19012).

---

<div class="post-metadata">

**Author:** ![robert7k](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@robert7k](https://discuss.gradle.org/u/robert7k)\
**Post date:** [March 17, 2018, 2:48pm UTC](https://discuss.gradle.org/t/how-does-buildship-create-the-classpath-file-for-eclipse/26252/3 "2018-03-17T14:48:01Z")

</div>

Donát,  
thank you for your response!

So I tried to use the `eclipse.classpath.file.whenMerged` block to reorder some classpath entries:

```
eclipse {
	classpath { 
		defaultOutputDir = file('war/WEB-INF/classes')
		file {
			whenMerged {
					def gwtClasspath = entries.find { it.path == 'com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER' }
					entries.remove gwtClasspath
					entries += gwtClasspath
			}
		}
	}
}

```

However, that doesn’t change the generated `.classpath` file.

But then, when leaving out the line `entries += gwtClasspath` line, the classpath entry gets removed. But how can I reorder classpath entries?

Thanks,

Robert

---

<div class="post-metadata">

**Author:** ![robert7k](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@robert7k](https://discuss.gradle.org/u/robert7k)\
**Post date:** [March 17, 2018, 3:03pm UTC](https://discuss.gradle.org/t/how-does-buildship-create-the-classpath-file-for-eclipse/26252/4 "2018-03-17T15:03:31Z")

</div>

I tried reordering the classpath entries:

```
		whenMerged {
				entries.sort { it.path }
				entries.reverse(true)
		}

```

This worked, this is the result:

```
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
	<attributes>
		<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
	</attributes>
</classpathentry>
<classpathentry kind="output" path="war/WEB-INF/classes"/>

```

So the reordering seems to work, but `<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">` will still end up last. Is there any way to get an entry behind this one?

---

<div class="post-metadata">

**Author:** ![donat](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/donat/32/7798_2.png) [@donat](https://discuss.gradle.org/u/donat)\
**Post date:** [March 19, 2018, 9:30am UTC](https://discuss.gradle.org/t/how-does-buildship-create-the-classpath-file-for-eclipse/26252/5 "2018-03-19T09:30:04Z")

</div>

Buildship appends the Gradle classpath container to the end of the classpath if it’s not defined in the `eclipse` plugin configuration. The following snippet fixes this behavior:

```gradle
eclipse {
   classpath {
        containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
   }
}

```

---

<div class="post-metadata">

**Author:** ![robert7k](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@robert7k](https://discuss.gradle.org/u/robert7k)\
**Post date:** [March 19, 2018, 5:52pm UTC](https://discuss.gradle.org/t/how-does-buildship-create-the-classpath-file-for-eclipse/26252/6 "2018-03-19T17:52:00Z")

</div>

Thank you, Donát. That’s exactly was I was looking for 🙂
