External dependencies download including sources.jar and javadoc.jar


is there a possibility to declare dependencies for a configuration and gradle will download the jar from the Maven repository including source and javadoc jars?

This works, but is there a shorter alternative?

  testCompile(group: 'junit', name: 'junit', version: '4.8.2', classifier: 'javadoc')
testCompile(group: 'junit', name: 'junit', version: '4.8.2', classifier: 'sources')

Regards, schoppi

The ‘eclipse’ and ‘idea’ plugins will do so automatically (if instructed). But if you need to grab the sources and javadoc Jars for your own purposes, you’ll ultimately have to make them separate dependencies as you did above.

In terms of shortening the code, you can use the shorthand notation ‘testCompile “junit:junit:4.8.2:javadoc”’. If you want to go further, you can create your own notation. Something like:

def dep(coords, javadoc = false, sources = false) {

def result = [dependencies.create(coords)]

if (javadoc) result << dependencies.create("$coords:javadoc")

if (sources) result << dependencies.create("$coords:sources")



testCompile dep(“junit:junit:4.8”, javadoc = true) // give me javadoc but no sources

Question is, do you really want Javadoc and sources on the same class path as the code.