After updating from gradle 6.3 to 6.4 and above script task outputs used as dependency don’t seem to work anymore.
To order my build logic I implemented some basic tasks in a gradle file gradle/tasks.gradle. If I implement the defined task in a sub-project and use it’s outputs as dependency in another sub-project, gradle 6.4 and above will not add proper dependencies between the corresponding tasks.
This is an MVCE to illustrate the problem:
gradle/tasks.gradle:
import java.time.LocalDateTime
class MvceTask extends DefaultTask {
@OutputFile
RegularFileProperty outputFile = project.objects.fileProperty()
@TaskAction
void execute() {
def tOutFile = outputFile.get().asFile
tOutFile.parentFile.mkdirs()
tOutFile.text = "MvceTask was here at " + LocalDateTime.now()
}
}
rootProject.ext.MvceTask = MvceTask
But with gradle 6.4 and above the dependency to project1:buildProject1 is ignored:
mvce>gradlew buildProject2 --dry-run
:project2:buildProject2 SKIPPED
BUILD SUCCESSFUL in 732ms
There are no hints on a breaking change with regard to this scenario in the 6.4 release notes. The only thing that looks like it might be related is the Precompiled Groovy DSL script plugins topic. But there are no migration steps mentioned.
Is this a known regression and how could I achieve the same behavior as in gradle 6.3?
Here the “artifact” we’re attaching is a task that actually generates a Jar. Doing so, Gradle can automatically track dependencies of this task and build them as needed. This is possible because the Jar task extends AbstractArchiveTask . If it’s not the case, you will need to explicitly declare how the artifact is generated.
in Sharing outputs between projects
As outputFile of MvceTask is a RegularFileProperty gradle should be able to pick up the information, that the buildProject1 task creates this file. Actually it was able to get this right in gradle 6.3. Thus I’m wondering why this broke without notice (or no notice I was able to find) and if this was on purpose.
I just found, that the documentation mentions my expectation as supported behavior. That is, this very likely is a bug.
A Provider of File, RegularFile or 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.
With the legacy API, I was not able to restore Gradle 6.3 behavior.
I remember that many things changed when variants where introduced in Gradle, and there could have been side effects. And this looks like it is a side effect of their introduction/maturation. Whether this is desired or a regression though, I cannot say. You could try to open an issue to get an answer from the staff.