# Incremental input NOT dependent on filename?

**URL:** <https://discuss.gradle.org/t/incremental-input-not-dependent-on-filename/27155>\
**Category:** Help/Discuss\
**Created:** [May 29, 2018, 7:55pm UTC](https://discuss.gradle.org/t/incremental-input-not-dependent-on-filename/27155 "2018-05-29T19:55:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjbell4](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rjbell4](https://discuss.gradle.org/u/rjbell4)\
**Post date:** [May 29, 2018, 7:55pm UTC](https://discuss.gradle.org/t/incremental-input-not-dependent-on-filename/27155/1 "2018-05-29T19:55:39Z")

</div>

If I use the `@Input` annotation on a file, it indicates that the task is dependent on the _path_ to that file, but not the contents of the file.

If I use the `@InputFile` (or `@InputFiles`) annotation, it indicates that the task is dependent on the _path and contents_ of the file.

What if I wanted to make a task dependent on the content of a file, but **_not_** the path to the file? Depending on how the file is processed, the name of the file might not matter. For example, if the input file changed from `foo-1.0.1.txt` to `foo-1.0.2.txt`, but the contents were unchanged, then for a particular task, it might make sense to consider it up-to-date (or to retrieve it from the build cache, etc.).

Interestingly, this case can be handled for build _outputs_. For example, if a task output was changed from `bar-1.0.1.txt` to `bar-1.0.2.txt`, but all the tasks inputs remained the same, then the contents of `bar-1.0.1.txt` could be retrieved from the build cache and used to create `bar-1.0.2.txt`. I believe that’s in part because outputs can be identified as a map, identifying which outputs are which files, regardless of the filenames involved.

Is there any way to achieve the same thing with task inputs? This would be a real benefit in a particular use case I’m facing.

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [May 29, 2018, 9:20pm UTC](https://discuss.gradle.org/t/incremental-input-not-dependent-on-filename/27155/2 "2018-05-29T21:20:56Z")

</div>

Hi Bob,

that is the reason for the [`@PathSensitive`](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/PathSensitive.html) annotation. For your use-case (only contents), you would need to annotate your inputs with `@InputFile` and `@PathSensitive(PathSensitivity.NONE)`. For more explanations, you can also check the [build cache guide](https://guides.gradle.org/using-build-cache/#relocatability) or the [userguide](https://docs.gradle.org/4.7/userguide/more_about_tasks.html#sec:task_input_output_annotations).

Cheers,  
Stefan

---

<div class="post-metadata">

**Author:** ![rjbell4](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rjbell4](https://discuss.gradle.org/u/rjbell4)\
**Post date:** [May 30, 2018, 2:59am UTC](https://discuss.gradle.org/t/incremental-input-not-dependent-on-filename/27155/3 "2018-05-30T02:59:39Z")

</div>

@Stefan_Wolf,

I had encountered that before, but that not realized that sensitivity could go as low as `NONE`. Thank you!

---

<div class="post-metadata">

**Author:** ![rjbell4](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rjbell4](https://discuss.gradle.org/u/rjbell4)\
**Post date:** [May 30, 2018, 3:07am UTC](https://discuss.gradle.org/t/incremental-input-not-dependent-on-filename/27155/4 "2018-05-30T03:07:51Z")

</div>

@Stefan_Wolf,

Perhaps you can answer one thing for me: If I annotate a method with `@InputFiles` and `@PathSensitive(PathSensitivity.NONE)`, do I need to ensure that the files as returned in the list from the method are always in the same order? That is, if I return `[foo, bar]` once and then `[bar, foo]`, another time, will that change the build cache key?

It seems to me to be likely that it would, but perhaps Gradle has a sneaky way around that.

Thanks,  
Bob

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [May 30, 2018, 8:43am UTC](https://discuss.gradle.org/t/incremental-input-not-dependent-on-filename/27155/5 "2018-05-30T08:43:50Z")

</div>

The comparison between input files and the build cache key does not depend on the order, no matter what path sensitivity is used. Only for `@CompileClasspath` and `@Classpath`, the order is taken into account.
