How can I generate JavaDocs for an Android project using the new Gradle build system?
Here is what I have come up with but it doesn't work.
task generateJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
ext.cp = android.libraryVariants.collect { variant ->
variant.javaCompile.classpath.files
}
classpath = files(ext.cp)
}
The main problem is that I do not get the appropriate android.jar on the classpath so some of the links in the JavaDocs are not resolved. I have to find a way to get all the necessary jars on the classpath.
Another problem with the approach I took is it collects the classpaths for all the build variants, rather than selecting one.
For Android gradle plugin 1.1.2+ (com.android.tools.build:gradle:1.1.2+)
libraryVariants - does not work anymore
use:
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
destinationDir = file("../javadoc/")
failOnError false
}
destinationDir = file("../javadoc/") - locate javadocs at root of project directory (in this way jenkins javadoc plugin could find it and show in special Document panel)
failOnError false - for suppress warnings that can cause fail build on jenkins
Gradle 1.11 - Gradle Plugin 0.10.0
Replace android.plugin.sdkDirectory
by android.sdkDirectory
android.libraryVariants.all { variant ->
task("generate${variant.name}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.links("http://d.android.com/reference/");
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
}
The solution I ended up settling on is as follows:
android.libraryVariants.all { variant ->
task("generate${variant.name}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.plugin.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
}
}
Xavier Ducrohet confirmed this is the way to do it (with caveats) on the adt-dev group, https://groups.google.com/forum/#!searchin/adt-dev/javadoc/adt-dev/seRizEn8ICA/bafEvUl6mzsJ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With