如何在Gradle Javadoc任务中提供生成的数据绑定类?



为了生成Javadoc,我使用了这个Gradle任务来提取AAR:

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"
}

它失败了,因为我在库模块内启用了androidx.databinding7.2.1:

> 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

如何将这些生成的源添加到classpath中?忽略类import似乎不是一个选择。或者javadoc必须依赖于产生这些(糟糕的时机)的任务?一般来说,exclude "**/ColorPickerDialogFragment.java"不是我要找的答案。

提取已构建的AAR并将其放在classpath上提供生成的类-
但是引用中间的classes.jar要优雅得多:

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/"
}
}
}
}

也可以先检查.exists():

javadoc.onlyIf {
new File("$buildDir/intermediates/aar_main_jar").exists()
}

相关内容

  • 没有找到相关文章