Output folder of sourceSet when running eclipseClasspath

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:

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

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

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:

eclipse.classpath.file.withXml {}

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

Hope that helps!

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

Thanks!

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:

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

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

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

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.

Did you see the beforeMerged hook?

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.

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!

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!