With this Gradle task I've used to extract AAR, in order to generate Javadoc:
task javadoc(type: Javadoc) {
doFirst {
configurations.implementation.filter { it.name.endsWith('.aar') }.each { aar ->
copy {
from zipTree(aar)
include "**/classes.jar"
into "$buildDir/tmp/aarsToJars/${aar.name.replace('.aar', '')}/"
}
}
}
failOnError false
options.linkSource true
options.links("https://docs.oracle.com/en/java/javase/11/docs/api/")
options.links("https://developer.android.com/reference/")
title = "Colorpicker Library ${versionName} API"
source = android.sourceSets.main.java.srcDirs
classpath = files(new File("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"))
classpath = project.files(android.getBootClasspath().join(File.pathSeparator))
classpath = fileTree(dir: "$buildDir/tmp/aarsToJars/")
configurations.implementation.setCanBeResolved(true)
classpath = configurations.implementation
destinationDir = file("${project.buildDir}/outputs/javadoc/")
exclude "**/BuildConfig.java"
exclude "**/R.java"
}
It fails since I've enabled androidx.databinding
7.2.1
inside the library module:
> Task :library:javadoc
...\ColorPickerDialogFragment.java:24: error: package com.acme.databinding does not exist
import com.acme.databinding.DialogColorPickerBinding;
^
...\ColorPickerDialogFragment.java:46: error: cannot find symbol
DialogColorPickerBinding mDataBinding;
^
symbol: class DialogColorPickerBinding
location: class ColorPickerDialogFragment
2 errors
How can I add these generated sources to classpath
? Ignoring the class import
doesn't seem to be an option. Or does javadoc
have to depend on the task, which generates these (bad timing)? In general, exclude "**/ColorPickerDialogFragment.java"
is not the answer I'm looking for.
CodePudding user response:
Extracting the built AAR and putting it on classpath
provides the generated classes -
but it's a whole lot more elegant to reference the intermediate classes.jar
already:
task javadoc(type: Javadoc) {
...
doFirst {
...
def aar_main = new File("$buildDir/intermediates/aar_main_jar")
if (aar_main.exists()) {
copy {
from aar_main
include "**/classes.jar"
into "$buildDir/tmp/aarsToJars/aar_main_jar/"
}
}
}
}
One can also check .exists()
before already:
javadoc.onlyIf {
new File("$buildDir/intermediates/aar_main_jar").exists()
}