Gradle eclipse plugin, ivy-publish and java sources location

I have generated the following ivy.xml through the ivy-publish plugin

<ivy-module version="2.0">
  <info organisation="xxxx" module="yyyy" revision="zzzz" status="integration" publication="20150216163301"/>
  <configurations>
    <conf name="default" visibility="public" extends="runtime"/>
    <conf name="runtime" visibility="public"/>
  </configurations>
  <publications>
    <artifact name="A" type="jar" ext="jar"/>
    <artifact name="B" type="jar" ext="jar"/>
    <artifact name="B_tests" type="jar" ext="jar"/>
  </publications>
  <dependencies>
    .. some dependencies
  </dependencies>
</ivy-module>

The important thing is that all my artifacts are custom artifacts generated with code like

ivy(IvyPublication) {
            artifact (...) {
             name "..."
             extension "jar"
            }
}

Then in another project with the eclipse plugin I have a dependency defined

dependencies {
    compile "xxxx:yyyy:zzzz"
}

All my artifacts are correctly retrieved (A, B, B_tests) but the .classpath generated by the eclipse plugin is weird.

It is filled with entries like

<classpathentry sourcepath="D:/Users/.../.gradle/caches/modules-2/files-2.1/xxxx/yyyy/zzzz/9cf4bc3736e220af4cfd6070121c60e0c3620533/yyyy-zzzz-sources.jar" kind="lib" path="D:/Users/.../.gradle/caches/modules-2/files-2.1/xxxx/yyyy/zzzz/de0148a2925a7182e89dc6c7ae1c7fe74f86017f/A-zzzz.jar" exported="true"/>

The sourcepath attributes uses yyyy-zzzz-sources.jar (so module-version-sources.jar) instead of the artifact in the path attributes. So even if my artifacts contain the .java files, the source code is not displayable. How shall I configure the ivy-publish (or the eclipse class) plugin so that the sourcepath is set to the artifact jar itself ?

(On less complicated projects with only a single regular publish artifact coming from ‘components.java’, everything is ok and the .classpath generated by other builds depending on this artifact is OK)

Do you have the sources bundled in the jar you published (e.g., A.jar)?

I think we look for an artifact with type source and classifier sources from Ivy repos. It’s not really configurable. But I can’t really tell from looking at the code if we’re failing to find a sources jar and somehow just assuming that it must exist on the Eclipse IDE generation side. The sources jar that the classpath lists definitely doesn’t exist locally?

No,

the source jar (module-version-sources.jar) does not exist locally.

All my custom artifacts are following this pattern :

artifact (xxxJar) {
   name "xxx"
   extension "jar"
}

and the Jar task is defined with

task xxxJar(type: Jar) {
 baseName "xxx"
 from sourceSets.xxx.java
 from sourceSets.xxx.output
}

So, yes, they include source files. But the type and classifier are not provided. I can try doing that.

Also, due to the fact that the ivy-publish plugin is still incubating, there is no clean way to define the dependencies section of the ivy.xml generated file. We are forced to use

from component.java'

in the IvyPublication block (to get the runtime dependencies). I don’t want to tweak the xml manually, and prefer to wait for a more complete ivy-publish plugin. But the drawback of doing that is that the default artifact of the java component is also included in my publication. This default artifact is named ‘module-version.jar’ So I guess this relates to the ‘module-version-sources.jar’ that the eclipse plugin tries to find…

Sterling, I tried your solution. I Changed my artifacts definitions from

artifact (xxxJar) {
   name "xxx"
   extension "jar"
}

to

artifact (xxxJar) {
   name "xxx"
   extension "jar"
   type "source"
   classifier "sources"
}

But this did not work.