I've created a custom Gradle task in Java (just put within buildSrc, so a local custom task)
public class ImageMergerTask extends DefaultTask{
public File directory;
@TaskAction
public void greet() {
System.out.println("hello from ImageMergerTask " + directory.toString());
}
@InputDirectory
public File getDirectory(){
return directory;
}
public void setDirectory(File directory){
this.directory = directory;
}
}
Used in the build.gradle like
task imageMerger(type : ImageMergerTask) {
directory file('src/main/resources/someFolder')
}
processResources.dependsOn(imageMerger);
My impression is that by annotating getDirectory() with @InputDirectory, it ought to only run this task if the contents of src/main/resources/someFolder changes, but it seems to run every time, always including in the console:
> Task :imageMerger
hello from ImageMergerTask C:\Users\richa\Documents\Development\starlight\src\main\resources\someFolder
How should a custom task declare its inputs to properly take advantage of up-to-date detection?
It seems that gradle doesn't make the up-to-date detection unless there is also an output directory. Adding this to the task made it correctly only run the task when the contents of the input directory changed
As found by @ThomasKläger the Gradle documentation confirms this