My environment consists of a mixture of Maven and Gradle projects which seems to cause issues with the downloading of source by the Gradle eclipse plug-in.
For example, I have 2 projects (A and B) both of which reference the same dependency (dropwizard in this case). Project A is built using Maven and Project B is built using Gradle. In ‘build.gradle’ for Project B I have the following:
repositories {
mavenLocal()
mavenCentral()
}
This is necessary because I need to reference SNAPSHOT resources that I have built and installed locally.
I start by removing both the ‘~/.m2’ directory and the ‘~/.gradle’ directory. I am then comparing the results of running ‘./gradlew cleanEclipse eclipse’ in Project B. If I do that first, before building project A then all of the entries in the resulting ‘.classpath’ file will refer to resources in the Gradle cache and they will all have source attachments if possible. So it works as expected.
If I first build Project A, then the local maven repository will be populated with the shared jar files. Doing the build in maven does not result in the source jars being downloaded (that will only happen on demand as you reference them in Eclipse). Then when I build Project B Gradle finds the dependencies in mavenLocal() (again as expected). However, it does not download the source jars and so the entries in the .classpath have no source attachments.
Once this happens there is no way to fix the problem. Eclipse doesn’t allow the source attachments to be updated, nor does it trigger a download once it notices that there are none. Re-running the ‘cleanEclipse’ and ‘eclipse’ tasks just results in exactly the same issue, unless you happen to have downloaded the source jars in the meantime. Changing the order of the repositories so that mavenLocal() is second will work around the issue, but that’s not ideal since in general you want the local repository to override the remote one.
It seems that the correct behavior here is for the eclipse plug-in to notice that the source jars are missing and attempt a download of them (as it does when using the gradle cache).