Add sources manually for a dependency which lacks of them

Did you try it with command?

$ gradle --daemon cleanEclipse eclipse

In my environment, I don’t have any antlr source code, so I try this script to modify…

  • output directory to be out directory instead of bin directory.
  • junit to have javadoc.
configurations {
  javadocDep (group: 'junit', name: 'junit', version: '4.12', classifier: 'javadoc') {
    exclude module: 'hamcrest-core'
  }
  testCompile 'junit:junit:4.12'
}
eclipse.classpath.file {
  withXml{xml ->
    def node = xml.asNode()
    node.classpathentry.find {it@kind == 'output'}.@path = 'out'
    node.classpathentry.find{
      it.@kind == 'lib' && it.@path.contains('junit')
    }.@javadocpath = configurations.javadocDep.asPath
  }
}

And a command gradle --daemon cleanEclipse eclipse generates .classpath file as follows.

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <!-- eclipse task generates bin as output path, but it is changed to out -->
  <classpathentry kind="output" path="out"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <!-- javadocpath attribute is not created by default, but it is added -->
  <classpathentry
      sourcepath="/Users/name/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/a6c3/junit-4.12-sources.jar"
      kind="lib"
      path="/Users/name/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973/junit-4.12.jar"
      javadocpath="/Users/name/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/941a/junit-4.12-javadoc.jar"/>
  <classpathentry
      sourcepath="/Users/name/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/1dc3/hamcrest-core-1.3-sources.jar"
      kind="lib"
      path="/Users/name/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a2/hamcrest-core-1.3.jar"/>
</classpath>

(for making it to easy to read, I inserted indentation in each attributes, and shorten hash code.)