Blake McBride
Blake McBride

Reputation: 412

Gradle file dependencies

I come from many years of experience with make. One thing that is baffling me is the use of task dependencies rather than file dependencies in Gradle. For example, if I have a C program that has these dependencies (in makefile format):

app : file1.o file2.o

file1.o : file1.c file1.h file2.h

file2.o : file2.c file2.h

So, both object files are dependent on file2.h and would be rebuilt if file2.h changed. However, if file1.h changed, only file1.o would be built.

How can I represent this in Gradle? I am mainly interested in how one can handle this in raw Gradle as opposed to using a plugin.

Thanks!

Blake McBride

Upvotes: 1

Views: 60

Answers (1)

Blake McBride
Blake McBride

Reputation: 412

The answer has to do with Gradle's incremental build support. It is documented at https://blog.gradle.org/introducing-incremental-build-support and https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:up_to_date_checks

Basically, for built-in tasks, Gradle internally calculates what the input and output files associated with a task are. It then uses this information to avoid executing unneeded tasks thus eliminating unneeded steps. For custom tasks, Gradle has a method, documented in the above links, to tell Gradle what the input and output files are for a particular task.

Upvotes: 0

Related Questions