I’m working on upgrading a project to Gradle 7 (from 6) which uses the shadow plugin to relocate some dependencies. The shadow plugin creates a jar when the task is run. The problem is the JavaDoc task only works if the jar already exists at the start of the task execution, even though the task depends on the shadowJar task so will be created during the build. Otherwise, Gradle complains the file does not exist.
Here is the task:
afterEvaluate { project ->
task androidJavadocs(type: Javadoc) {
def releaseVariant = android.libraryVariants.matching { variant -> variant.name == "release" }.iterator().next() // not sure if this is the best way to do this, but I'm only interested in creating docs for the release variant
source = android.sourceSets.main.java.source
classpath += project.files(
releaseVariant.javaCompile.classpath, // this contains the path to the jar which is created in the ":dagger-compiler-shadow:shadowJar" task
project.android.getBootClasspath().join(File.pathSeparator),
files("$buildDir/intermediates/classes/release")
)
title = null
options.noTimestamp(false)
options.doclet = "com.google.doclava.Doclava"
options.docletpath = configurations.doclava.files.asType(List)
dependsOn ':dagger-compiler-shadow:shadowJar' // this is not required as the task is performed without it, but here for clarity
}
}
Previously with Gradle 6, the classpath was:
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
And that seemed to work fine, but this doesn’t work in gradle 7, it complains “compile” doesn’t exist on configurations.
How can I run the task before gradle checks if the file exists, or prevent gradle from checking if the file exists until it is required? I tried using FileTree but it seems this doesn’t pick up the jar when the task is run, so presumably matches files at the start of task execution before the jar is created.