Add jar to javadoc classpath that is created at build time

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 -> == "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 =
        classpath += project.files(
                releaseVariant.javaCompile.classpath, // this contains the path to the jar which is created in the ":dagger-compiler-shadow:shadowJar" task
        title = null
        options.doclet = ""
        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.

I didn’t read the full code, but if your only problem is, that configurations.compile is not found anymore, then just use the appropriate replacement. The compile configuration is deprecated since many many years and also was meant to declare dependencies, not to be resolved. Use configurations.compileClasspath instead.

Thanks for your response, but no, that is not the issue. The issue is that a jar in the classpath I have defined is created by a task that the JavaDocs task depends on, but does not exist at the start of the run, and so Gradle throws an error that the file cannot be found.

However, your suggested classpath does not work either:

Could not get unknown property ‘compileClasspath’ for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.

I was able to resolve this issue. There is a dependency heirarchy of :mockrxandroidble > :rxandroidble > :dagger-library-shadow:shadowJar. For some reason, :rxandroidble:androidJavadocs worked fine, but :mockrxandroidble:androidJavadocs had the missing file error. The shadow jar was in the releaseVariant.javaCompileProvider.get().classpath even though it wasn’t required for this task. I simply removed the shadow jar from the classpath for the :mockrxandroidble:androidJavadocs task only and it works fine.