How to download sources for a specific artifact and attach them to this artifact (to use within Eclipse)

(k naike) #1

I’m working with Gradle 1.6 and Eclipse (with the STS plugin).

I’ve some private artifacts that I use as lib for other projects. They are stored in a private repository. Also, a lot of them has no sources (old artifacts but still useful). For all of my news artifact, I’ve generated sources that I want to use.

For the moment, I’m using the following configuration in an external buildscript:

eclipse {
  classpath {
    downloadSources = true
     downloadJavadoc = false

The problem with this configuration is, when I read the log, I see that Gradle is trying to download all sources of all artifact (even old artifacts that have no sources). I noted that this configuration make my Gradle refresh dependencies to be very slow. But at the end, I’ve got the sources (of artifacts that have sources) and I can reach them within eclipse (open declaration of a method, etc)

Now, I’m trying another approach to reduce the time of my build (or refresh). So I put downloadSources to false in the eclipse classpath configuration and I would like to use the classifier attribute in the dependencies configuration.

For example:

compile(group: '', name: 'module', version: '1.2') { changing = true ; transitive = false;}
compile(group: '', name: 'module', version: '1.2', classifier: 'sources') { changing = true ; transitive = false;}

With this configuration, the jar and the source are downloaded by Gradle. But the problem is that the source is not attached.

In Eclipse, when I try to open the declaration of a method that is in the jar, I’ve got the following message from Eclipse:

Source not found
The Jar of this class belongs to container 'Gradle dependencies' which does not allow modifications to source attachments on its entries.

How can I do solve my problem? How can I use the classifier attribute instead of the eclipse.classpath.downloadSource ?

Thank in advance for any help.