Hi,
I’m trying to do something similar to this ( Artifact builtBy task is not called when resolving a configuration ), where a project exposes artifacts through a configuration that is consumed by another project as a dependency, using
implementation(project(":builder"), configuration = "builderConfig")
From linked question, I understand that the artifact builtBy
task is not automatically invoked (I don’t understand why it couldn’t, but let’s skip on this).
However, I create the artifact using outputs from the builtBy
task, with lazy evaluation:
val builderTask = tasks.register("builderTask") {
outputs.file("some_file")
doLast { /* produce the file */ }
}
artifacts {
add("builderConfig", builderTask.map { it.outputs.files.singleFile() }) {
builtBy(builderTask)
}
}
This artifact notation (a Provider that resolves to a File) is listed in ArtifactHandler as legit, and the javadocs there explicitly say:
A {@link org.gradle.api.provider.Provider} of {@link java.io.File}, {@link org.gradle.api.file.RegularFile} or {@link org.gradle.api.file.Directory}. The information for publishing the artifact is extracted from the file or directory name. When the provider represents an output of a particular task, that task will be executed if the artifact is required.
Shouldn’t my task be executed when the configuration is resolved by the consuming project? If not why, and how can I achieve what I want - executing the task automatically when resolving the configuration?
The configuration is consumed in another project by a plugin (Android Gradle Plugin), so there’s no task that I could add a “dependsOn” to builderTask. For those who know AGP, it fails in the jetifier step.
Caused by: java.io.FileNotFoundException: /my/file/path/some_file (No such file or directory)
at kotlin.io.FilesKt__FileReadWriteKt.readBytes(FileReadWrite.kt:63)
at com.android.tools.build.jetifier.processor.Processor.transform2(Processor.kt:257)
at com.android.build.gradle.internal.dependency.JetifyTransform.transform(JetifyTransform.kt:129)
… 86 more