Search code examples
eclipsegradlegradle-eclipsebuild.gradleeclipse-classpath

How to add a concrete reference to the classpath in Eclipse project by gradle?


All examples that I see in the documentaton, that tell how to add an entry to the Eclipse project classpath by build.gradle file are too common. They say nothing how to add an entry:

<classpathentry exported="true", kind="con" path="GROOVY_SUPPORT"/>

Doc or the book "Gradle Effective Implementation Guide" are quite useless with advices as

  //closure executed after .classpath content is loaded from existing file
  //and after gradle build information is merged
  whenMerged { classpath ->
    //you can tinker with the Classpath here
  }

Solution

  • You can add another classpath entry by creating an instance of org.gradle.plugins.ide.eclipse.model.Container:

    eclipse {
        classpath {
            file {
                whenMerged { classpath ->
                    def groovySupportContainer = new org.gradle.plugins.ide.eclipse.model.Container('GROOVY_SUPPORT')
                    groovySupportContainer.exported = true
                    classpath.entries << groovySupportContainer
                }
            }
        }
    }