spotless icon indicating copy to clipboard operation
spotless copied to clipboard

Gradle build cache miss due to volatility of SpotlessTask.steps input

Open jprinet opened this issue 8 months ago • 7 comments

Summary

  • Gradle version: any
  • Spotless version: 7.0.0.BETA1
  • OS: any

Spotless configuration

See this example in the JUnit5 project

Expected behavior

Run the build twice without changing the code and get a Gradle build cache hit on spotlessJava task

Current behavior

A cache miss occurs in the second build scan

First Build Scan® Second Build Scan®

Due to the SpotlessTask.steps value being different in the two builds: Screenshot 2024-06-12 at 4 06 22 PM

Steps to reproduce

cd /tmp
git clone [email protected]:junit-team/junit5.git junit5-1 --depth 1
git clone [email protected]:junit-team/junit5.git junit5-2 --depth 1
cd junit5-1
gw clean :junit-platform-console:spotlessJava -Dgradle.user.home=../guh -Dgradle.cache.remote.enabled=false --scan
cd ../junit5-2
gw clean :junit-platform-console:spotlessJava -Dgradle.user.home=../guh -Dgradle.cache.remote.enabled=false --scan

Reasons

The SpotlessTask.steps is declared as task input but deserializing/serializing the collection is not consistent

Fix

Use a consistent representation of the input by using the steps name. This assumes that the step name is unique.

See this Build Scan®️ illustrating the build cache hit with the fix

jprinet avatar Jun 12 '24 14:06 jprinet