I have configured gradle build cache for my gradle project; however I'm seeing cache misses because of some specific files between linux (ci, wsl) and windows.
Here's an example of a file that works fine, and one that doesn't:
Windows line endings on Windows
src/main/kotlin/com/example/myservice/Application.kt / 2cb571d81042a8f959e144defd9f18b8
src/main/resources/logback-spring.xml / 7e3ed1680c889bf1cc5450a0c6e8620f
Unix line endings on Linux
src/main/kotlin/com/example/myservice/Application.kt / 2cb571d81042a8f959e144defd9f18b8
src/main/resources/logback-spring.xml / 09219d6006f7c1bc7de29d36fb706fad
Note that gradle computes the same hash on Windows and Linux for Application.kt
, but a different hash for a resource file like logback-spring.xml
.
In this example, it means that my gradle task compileTestKotlin
misses the cache on windows, and has to re-compile. On linux, I get a cache hit, and the build does not have to re-compile.
The only differences between these files in both cases are line endings. If I pull logback-spring.xml
on Windows, call dos2unix
on logback-spring.xml
to convert line endings to unix, and rerun the build, I get the correct hash for logback-spring.xml
and I get a cache hit for the task.
So, gradle seems to be normalizing line endings correctly for Application.kt
, but not for logback-spring.xml
.
How can I fix this?