Generate ScalaIDE Eclipse metadata for Scala projects

The Eclipse plugin generates metadata for Scala projects. When using the ScalaIDE and importing, the build is initially broken with the error: ‘Cannot find Scala library on the classpath. Verify your build path!’ This can be resolved manually by clicking Scala->‘Add Scala library to Build Path’. This extra step is automatically handled for Maven users via m2eclipse-scala, as explained in the ScalaIDE faq.

The missing step appears to be that the ScalaIDE expects have its classpath container added to the .classpath file. The import builds successfully if the entry is added manually:

<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>

The question is who is responsible for adding this missing metadata to the Eclipse project? Is it the Scala IDE, Gradle, Gradle STS, or the developer? After discussing this with the Gradle STS team, STS-2868, they suggest that it is probably Gradle’s responsibility due to the Eclipse plugin already adding Scala support to the .project file.

If it is the developer’s, what would be the proper build script update to fix it automatically? I am a little weary of rewriting the raw XML after a previous bad experience due to subtle mistakes. I wrote the following snippet which appears to work,

eclipse.classpath.file.withXml { provider ->
  def attributes = [kind: "con", path: "org.scala-ide.sdt.launching.SCALA_CONTAINER"]
  provider.asNode().appendNode("classpathentry", attributes)


The following snippet also works, is shorter, and less of a hack.

eclipse.classpath.containers += ["org.scala-ide.sdt.launching.SCALA_CONTAINER"]

I agree that this should be handled by Gradle’s ‘eclipse’ plugin. Want to send a GitHub pull request?

Great, sent pull request.