A few days ago I upgraded to the new Android Studio Arctic Fox release, which also now requires Gradle 7
Prior to the upgrade, I had the following javadoc task, which worked perfectly
def javaDocsAllowList = [
"com/mycompany/SomeFile.java",
"com/mycompany/OtherFile.java",
...
]
task javadocs(type: Javadoc) {
source android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.compile
include javaDocsAllowList
destinationDir = file("./docs/javadoc")
}
Now though, it's all broken.
First error was
Could not get unknown property 'compile' for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer
so I change the classpath line to:
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.implementation
Then I get
Resolving dependency configuration 'implementation' is not allowed as it is defined as 'canBeResolved=false'.
so I add
configurations.implementation.setCanBeResolved(true)
THEN I get a bunch of errors that it cannot find symbol for @Nullable and other attributes.
Other stackoverflow answers suggest adding this, which I do:
afterEvaluate {
javadocs.classpath += files(android.libraryVariants.collect { variant ->
variant.javaCompileProvider.get().classpath.files
})
}
This fixes the errors resolving @NonNull, etc, but now I am left with a bunch of errors where JavaDoc cannot resolve my own code, such as:
void addNotificationsListener(@NonNull NotificationsListener listener); (cannot find symbol NotificationsListener)
These seem to be reduced when I add more files to the AllowList, but I explicitly do not want to generate documentation for these other files. Help!
Why did Gradle 7 break all the JavaDocs and how can I fix it?
(recap: this is my failing task:)
task javadocs(type: Javadoc) {
source android.sourceSets.main.java.srcDirs
configurations.implementation.setCanBeResolved(true)
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.implementation
include javaDocsAllowList
destinationDir = file("./docs/javadoc")
afterEvaluate {
javadocs.classpath += files(android.libraryVariants.collect { variant ->
variant.javaCompileProvider.get().classpath.files
})
}
}
Update: based on suggested gist https://gist.github.com/Robyer/a6578e60127418b380ca133a1291f017?, I changed my task to the following:
task javadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
android.libraryVariants.all { variant ->
if (variant.name == 'release') {
owner.classpath += variant.javaCompileProvider.get().classpath
}
}
include javaDocsAllowList
destinationDir = file("./docs/javadoc")
}
However this makes no difference; it still gets the same error where it cannot resolve my own code
void addNotificationsListener(@NonNull NotificationsListener listener); (cannot find symbol NotificationsListener)`