Hi,
I have a project which fetches proto-files from another repository in order to be able to generate a gRPC-client.
This behaviour is summarized in a custom task, which is readily available in my public repository as sample.
tasks.register<Exec>("fetchProtoFiles") {
description = "Fetching proto files from 'foo-server' to generate gRPC client."
onlyIf { !file("build/cloned").exists() }
workingDir(".")
commandLine(
"git",
"clone",
"--depth=1",
"--branch=main",
"--single-branch",
"https://github.com/patient-developer/foo-server.git",
"build/cloned/"
)
doLast {
copy {
from("build/cloned/src/main/proto/")
into("build/proto/")
}
}
}
Due to the onlyIf closure I receive the desired result, that generateProto is UP-TO-DATE since fetchProtoFiles is SKIPPED.
$ ./gradlew build --console=verbose -Duser.language=en
> Task :protobufDummy UP-TO-DATE
> Task :extractIncludeProto UP-TO-DATE
> Task :extractProto UP-TO-DATE
> Task :fetchProtoFiles SKIPPED
> Task :generateProto UP-TO-DATE
> Task :compileJava UP-TO-DATE
However, the Task is now SKIPPED.
In order to be aligned with incremental build, it would be desirable to define inputs and outputs, no? To inspect this approach, I did setup the branch inputs-outputs.
I am struggeling to define the inputs and outputs of that task. The output-directory would be build/proto- no? But when setting the input-directory to build/cloned it fails if the directory is not available, i.e., when doing a first checkout or gradle clean, e.g.,
$ ./gradlew clean build --console=verbose -Duser.language=en
I receive
> Task :clean
> Task :protobufDummy UP-TO-DATE
> Task :extractIncludeProto
> Task :extractProto
> Task :fetchProtoFiles FAILED
[Incubating] Problems report is available at: file:///***/multi-project/build/reports/problems/problems-report.html
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':fetchProtoFiles' (type 'Exec').
- Type 'org.gradle.api.tasks.Exec' property '$1' specifies directory '***\multi-project\build\cloned' which doesn't exist.
Reason: An input file was expected to be present but it doesn't exist.
Possible solutions:
1. Make sure the directory exists before the task is called.
2. Make sure that the task which produces the directory is declared as an input.