Gradle eclipse classpath containers

Is there any way to create separate eclipse classpath containers for each configuration ? The containers would hold the jars specific to a configuration.

You could use one of the provided hooks to post-process the .classpath file.

Does that mean I have to write my own IClasspathContainer implementation first and then specify it as a path on my classpathentry ? I did not find any resource showing how to do this just by post processing the .classpath file and what kind of child elements would accept.

Thanks very much,


The DSL reference has some examples. It may also help to check the user guide and the samples in the full Gradle distribution.

Hi Peter,

Thanks for your quick replies ! I’ve had a look at the examples and the doc but none of them seem to have helped. I’ll try to make a clearer explanation of what I want to achieve. So,

  1. If I define some custom configurations, I want to create 1 container for each configuration. I know how to create custom containers, it’s in the docs.

  2. I want to add the jars in a specific configuration to the relevant class path container. This is the bit where I am having a problem because the problem is not about manipulating the resulted class path entries in the .classpath file but that a class path entry of kind=“con” in the eclipse .classpath file is a logical reference to an IClasspathContainer implementation. E.g :

<classpathentry exported="true" kind="con" path="com.springsource.sts.gradle.classpathcontainer"/>

This is the class path container implementation in Spring STS gradle plugin. The above class path entry does not hold any static references to any jar file, instead, they jars are resolved according to the IClasspathContainer implementation at runtime (Eclipse’s).

Currently, when Gradle generates eclipse the class path file, it writes entries of kind=“lib” which can refer a jar file and therefore can be seen in Eclipse under Referenced Libraries.

I think this problem can only be solved by a gradle plugin, but unfortunately I cannot use STS’s plugin.

Am I missing something ?

Best Regards,


this line has been removed when I posted earlier … so I’m reposting the missing line after point 2.

<classpathentry exported="true" kind="con" path="com.springsource.sts.gradle.classpathcontainer"/>

I can’t follow you in 2. In general, you can either use the Gradle Eclipse plugin (which ships with Gradle and generates ‘.classpath’, ‘.project’, etc.), or use the STS Gradle plugin. You cannot mix the two. My suggestion to tweak the generation of the ‘.classpath’ file is about the former, and I can’t see why it couldn’t be made to work (with some effort of course). After all, you have full control over the content of the generated files.

Hi again Peter,

Sorry for my late reply. I am quite busy these days … I’ll try to put some sample code of what i want …

Assuming I have created a container in the class path like this

eclipse.classpath {
 containers 'my.container'

Now, eclipse expects ‘my.container’ to be an implementation of IClasspathContainer. Am I right about this ? As I did not find an IClasspathContainer implementation in Gradle that knows how to resolve gradle dependencies, I suppose I cannot use this approach

Creating a USER_LIBRARY container and manipulating the XML ( .classpath )

configurations {
  eclipse.classpath {
   containers 'org.eclipse.jdt.USER_LIBRARY/MY_CONTAINER'
          file {
               beforeMerged { classpath ->
                       classpath.entries.findAll { entry -> entry.kind == 'con' && entry.path == 'org.eclipse.jdt.USER_LIBRARY/MY_CONTAINER' }
//Here I want to iterate over the jars in MY_CONFIGURATION and associate those jars to MY_CONTAINER.
//How do I do the association between the jars in my configuration and my container
 //so that in eclipse I can see the jars in MY_CONFIGURATION under MY_CONTAINER
//user library container ? Is it possible ?

Was I confusing again ?