Gradle publish ".java" source code to a repository

I would like to know how it is possible within a “build.gradle” file to specify that I want the “gradle publish” command not only package the .java sources to a .jar in a repository area, but also, I would like to “copy” the .java in the repository area.

I would then be able to work with Eclipse, with the published-modules declared in the .classpath I would like to get access to the .java source code from the Eclipse Gui (with the ‘F3’ key for example).

I guess it cannot be a simple ‘Copy Task’, because Eclipse relies on the ".classpath’ file which contain the path to the published .jar modules and it should exist a connexion between these .jar and the “.java” I want to publish.

Thanks a lot for your help !

The section on publishing custom artifacts shows an example of how to specify the task to create the sources JAR and then add it as an artifact in the User Guide.

The JAR file is published with the same identifying information, so they are linked that way. The only difference is the “sources” classifier. Eclipse will also download the sources JARs for dependencies and attach them automatically when using the Pivotal Eclipse Plugin that adds Gradle support. I’m not sure if the new Buildship plugin does this yet.