./gradlew clean vs fastClean.sh
I had a CI step that was responsible for assembling all affected "sample apps", and it built them one after the other, because the builds were independent of each other and would often fail due to files left over from their siblings. This required that I run ./gradlew clean between each assemble.
This became a huge problem, because at worst this required configuring 1600 modules, and at best (with configure on demand) it still required hundreds. This led to each clean taking 2-3 minutes of compute time, and with as many as ~100 sample apps spread across shards, it was painfully inefficient.
This bothered me greatly, because as far as I can tell, the main thing that ./gradle clean does is delete the /build directory that each module has, and I knew that even a simple shell script to delete each of those directories wouldn't take 2-3 minutes.
My first attempt was a brute force "find" and "delete", and sure enough, it was faster, but it had me wondering if there was an even faster way. I experimented with a few other methods, and then it occurred to me that the army of developers that have contributed to git clean have probably found the fastest and most efficient way to do so.
Sure enough, I ran it through the same tests as the others and it was consistenly faster at deleting the /build directories. In order to be sure that it didn't delete anything else, I had to make sure it paid attention to the project level exclusions, and I also added a few custom ones of my own, but ultimately it's just git clean
# Step 3: Add lines from .git/info/exclude (skip empty lines and comments)
if [[ -f .git/info/exclude ]]; then
while IFS= read -r line; do
# Skip comments and empty lines
[[ -z "$line" || "$line" =~ ^\s*# ]] && continue
exclusions+=("$line")
done < .git/info/exclude
fi
# Step 4: Run git clean with expanded -e arguments
local cleanCommand="git clean -fxd ${exclusions[@]/#/-e } > /dev/null"
echo "🔧 $(tput setaf 2)$cleanCommand$(tput sgr0)"
This saves a HUGE amount of time on CI builds, and also my local builds :P
I'm debating trying to override the native ./gradlew clean for my developers to use this command, but it's on my backlog for now.