# Output folder of sourceSet when running eclipseClasspath

**URL:** <https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277>\
**Category:** Old Forum Archive\
**Created:** [September 13, 2012, 1:15pm UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277 "2012-09-13T13:15:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric\_deandrea](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@eric\_deandrea](https://discuss.gradle.org/u/eric_deandrea)\
**Post date:** [September 13, 2012, 1:15pm UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/1 "2012-09-13T13:15:00Z")

</div>

I’m tinkering with using gradle’s eclipse plugin to keep my .project & .classpath files up to date. Everything seems to be going ok except for 1 thing I can’t seem to figure out - when the eclipseClasspath task executes it generates src classpathentry’s for all of my source sets but it doesn’t seem to generate an “output” attribute on the classpathentry element.

For example, when I first set up my eclipse classpath, I set it up like this:

```gradle
<classpath>
 <classpathentry kind="src" output="target/classes/main" path="src/main/java"/>
 <classpathentry excluding="**" kind="src" output="target/resources/main" path="src/main/resources"/>
 <classpathentry kind="src" output="target/classes/test" path="src/test/java"/>
 <classpathentry excluding="**" kind="src" output="target/resources/test" path="src/test/resources"/>
 <classpathentry kind="src" output="target/classes/main" path="target/generated-sources/main/jaxb"/>
 <classpathentry kind="src" output="target/classes/test" path="target/generated-sources/test/jaxb"/>
 <classpathentry exported="true" kind="con" path="com.springsource.sts.gradle.classpathcontainer"/>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_31"/>
 <classpathentry kind="output" path="target/classes/main"/>
</classpath>

```

The resulting .classpath file after running eclipseClasspath looks like this (notice its missing the output attribute in the classpathentry):

```gradle
<classpath>
 <classpathentry kind="src" path="src/main/java"/>
 <classpathentry kind="src" path="target/generated-sources/main/jaxb"/>
 <classpathentry kind="src" path="src/main/resources"/>
 <classpathentry kind="src" path="src/test/java"/>
 <classpathentry kind="src" path="target/generated-sources/test/jaxb"/>
 <classpathentry kind="src" path="src/test/resources"/>
 <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 <classpathentry kind="output" path="target/classes/main"/>
</classpath>

```

---

<div class="post-metadata">

**Author:** ![Szczepan\_Faber](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szczepan_faber/32/213_2.png) [@Szczepan\_Faber](https://discuss.gradle.org/u/Szczepan_Faber)\
**Post date:** [September 14, 2012, 5:51am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/2 "2012-09-14T05:51:00Z")

</div>

Output property of the Eclipse classpath entry is not modelled at the moment in our Eclipse plugin API. The only way you can configure this atm would be using the xml hooks:

```gradle
eclipse.classpath.file.withXml {}

```

For more examples please refer to DSL reference on the EclipseClasspath type.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![eric\_deandrea](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@eric\_deandrea](https://discuss.gradle.org/u/eric_deandrea)\
**Post date:** [September 14, 2012, 11:21am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/3 "2012-09-14T11:21:00Z")

</div>

Thats the answer I was expecting based on the documentation I’ve been reading.I was hoping for a different answer though!

Thanks!

---

<div class="post-metadata">

**Author:** ![eric\_deandrea](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@eric\_deandrea](https://discuss.gradle.org/u/eric_deandrea)\
**Post date:** [September 14, 2012, 11:27am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/4 "2012-09-14T11:27:00Z")

</div>

Let me ask another question about the EclipseClasspath type. If I’m merging an existing.classpath and the existing one has a container entry in it, like this:

```gradle
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_31"/>

```

It seems that after merging gradle’s model with the existing .classpath (by running gradle eclipse without first running cleanEclipse) that I get an additional container added in by gradle, resulting in a .classpath file that has both of these in it:

```gradle
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_31">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true">

```

Is there a way during the merge that if a container element already exists to tell gradle not to add its own?

---

<div class="post-metadata">

**Author:** ![Szczepan\_Faber](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szczepan_faber/32/213_2.png) [@Szczepan\_Faber](https://discuss.gradle.org/u/Szczepan_Faber)\
**Post date:** [September 17, 2012, 10:05am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/5 "2012-09-17T10:05:00Z")

</div>

Sure, use the whenMerged hook to modify the containers after the merge. Hope that helps!

---

<div class="post-metadata">

**Author:** ![eric\_deandrea](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@eric\_deandrea](https://discuss.gradle.org/u/eric_deandrea)\
**Post date:** [September 17, 2012, 11:11am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/6 "2012-09-17T11:11:00Z")

</div>

But then how do I know which container was there before the merge and which container was added by the Gradle java plugin? Basically if the user already had configured a java runtime container, I don’t want gradle to add in a 2nd.

---

<div class="post-metadata">

**Author:** ![Szczepan\_Faber](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szczepan_faber/32/213_2.png) [@Szczepan\_Faber](https://discuss.gradle.org/u/Szczepan_Faber)\
**Post date:** [September 18, 2012, 5:34am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/7 "2012-09-18T05:34:00Z")

</div>

Did you see the beforeMerged hook?

---

<div class="post-metadata">

**Author:** ![eric\_deandrea](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@eric\_deandrea](https://discuss.gradle.org/u/eric_deandrea)\
**Post date:** [September 18, 2012, 11:41am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/8 "2012-09-18T11:41:00Z")

</div>

I saw the beforeMerged hook. What I’m trying to figure out is if there is already a java runtime container present in the .classpath then I don’t want gradle to add another. It seems that right now if there is already a java runtime container present then when I run the eclipseClasspath task it adds another java runtime container.

---

<div class="post-metadata">

**Author:** ![Szczepan\_Faber](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szczepan_faber/32/213_2.png) [@Szczepan\_Faber](https://discuss.gradle.org/u/Szczepan_Faber)\
**Post date:** [September 21, 2012, 9:24am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/9 "2012-09-21T09:24:00Z")

</div>

The beforeMerged hook gives you access to the classpath model object that contains all the information that already exists in the .classpath file. For example, you can check what are the currently configured containers in the classpath file.

whenMerged hook gives access to the classpath model object that contains merged model (existing file + Gradle info from the build script). You can check what are the containers that will be written to the file (next step). From your description, I think whenMerged hook is what you need.

For more information on how the beforeMerged/whenMerged hooks work please refer to the user guide.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![eric\_deandrea](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@eric\_deandrea](https://discuss.gradle.org/u/eric_deandrea)\
**Post date:** [September 21, 2012, 11:43am UTC](https://discuss.gradle.org/t/output-folder-of-sourceset-when-running-eclipseclasspath/7277/10 "2012-09-21T11:43:00Z")

</div>

Ahh ok - so whenMerged is called BEFORE the file is actually written out, so it gives you the opportunity to “muck” with the model one last time before it is written out to file. I was under the assumption that whenMerged was called after the file was written.

Thanks for the info - I’ll give it a try!
