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?
Why doesn't gradle only resolve dependencies during execution? (i.e. Why do I see this error for every gradle task?)
How to I tell gradle to build core.jar before executing this custom task?
The Jar is created under the $project/build/libs/ folder.
If you are using an IDE, go to run, edit configurations, gradle, select gradle task and update the environment variables. See the picture below. Alternatively, if you are executing gradle commands using terminal, just type 'export KEY=VALUE', and your job is done. Save this answer.
Because variant.javaCompiler.classpath.files is already files type. You can try both statements:
classpath += variant.javaCompiler.classpath.files
Or as you mention before:
classpath += files(variant.javaCompiler.classpath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With