How configure Gradle to generate Javadoc for Testing classes (JUnit)

Hello

Thanks by the reply.

I have tried both solutions, below my experience.

For the first approach I did realize that is mandatory declare

plugins {
  id 'java'
}
javadoc {
  classpath += sourceSets.test.compileClasspath
  source += sourceSets.test.allJava
}

In the beginning of the gradle.build file, otherwise I get the following error message:

> startup failed:
  build file '/.…some path…./build.gradle': 9: only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
  
  See http://gradle.org/docs/2.2.1/userguide/plugins.html#sec:plugins_block for information on the plugins {} block
  
   @ line 9, column 1.
     plugins {
     ^
  
  1 error

(1) Pls confirm that is normal

Ok, when is declared in the beginning I can execute the javadoc command.

The command generates the expected, both main and test classes together in one javadoc.

But always ends the command throwing this exception

Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/javadoc'' finished with non-zero exit value 1
Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.2.1-bin.zip'.

I don’t know what is wrong.

About the second approach

// creating javadoc task for test code
task testJavadoc(type: Javadoc) {
  source = sourceSets.test.allJava
  classpath = sourceSets.test.compileClasspath
  // if not changed the destinationDir, the javadoc for production code is overridden.
  destinationDir = file("${buildDir}/docs/testjavadoc")
}

Does not work, never is generated the testjavadoc folder. Something is missing there

Thanks by your support.