Gradle cannot find module's output jar when executing custom task

tir38 :

I have a Gradle project with three modules, each with nested dependency on the next:

android app module, which depends on...
   android lib module, which depends on ...
      java lib module (called core)

Inside my lib module I'm trying to create a custom task (to generate javadocs, but that's prob not relevant)

library/build.gradle:

apply plugin: 'com.android.library'

android {
    ...
}

android.libraryVariants.all { variant ->
    task("${variant.name}Docs", type: Javadoc) {
        failOnError true
        source = variant.javaCompiler.source
        classpath = files(((Object) android.bootClasspath.join(File.pathSeparator)))
        classpath += files(variant.javaCompiler.classpath.files) // THIS LINE IS CAUSING ERROR
    }
}

dependencies {
    implementation project(':core')
    ...
}

The problem is that when I run any Gradle task (even Gradle clean), I get an error about not finding core.jar

org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':library'.

Caused by: org.gradle.api.artifacts.transform.ArtifactTransformException: Failed to transform file 'core.jar' to match attributes {artifactType=android-classes} using transform JarTransform

Caused by: org.gradle.api.InvalidUserDataException: Transform output file ******/core/build/libs/core.jar does not exist.

I guess this is happening because Gradle is looking for all files needed library's classpath (including core.jar) during the configuration phase. But why?

  1. Why doesn't gradle only resolve dependencies during execution? (i.e. Why do I see this error for every gradle task?)

  2. How to I tell gradle to build core.jar before executing this custom task?

tir38 :

I don't really know why this worked, but simply removing the .files from the problem line solved things:

classpath += files(variant.javaCompiler.classpath)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=457216&siteId=1