How do I write a test to validate my use of @InputFiles or any other types of UP-TO-DATE annotations?

I’m trying to write a test to validate my use of @InputFiles on a plugin written in Java.

I’ve finally arrived at a solution that uses my method for checking a List<File> (directories)

  1. Uses a getXYZ name, not some random name
  2. Traverses all the directories and returns a file collection
  3. Use @Internal on the regular getter so I don’t get validation warnings.

So now I have a method that looks like this:

 @Optional
 @InputFiles
 public FileCollection getDirectoriesAsInputFiles() {
   if (directories == null) {
     return null;
   }
   FileCollection files = project.files();
   for (File directory : directories) {
     files = files.plus(project.fileTree(directory));
   }
   return files;
 }

@Internal
public List<File> getDirectories() {
  return directories
}

However, it took me a couple of rounds of manually testing this to actually verify that the UP-TO-DATE check works AND is actually calling this method.

Is there a way to write a test to verify that the UP-TO-DATE check on a task is actually calling methods I think it is?

You could use TestKit to write a functional test for your task and check the BuildOutcome

Eg

  1. run your task first - SUCCESS
  2. run the task again without updating a file - UP-TO-DATE
  3. change an input file and run again - SUCCESS

Thanks, I was afraid I was going to have to write a pretty involved test. I guess I’ll do that for this special method.

Secondarily. It would be nice if gradle caught a method with @Input...on non getters during the :validateTaskProperties phase. Perhaps I’m on too old a version?