Skip to content

Commit

Permalink
build: use on-demand configuration for spotless script
Browse files Browse the repository at this point in the history
... to drastically increase performance of updates for individual files.
  • Loading branch information
stempler committed Aug 20, 2024
1 parent 07a3ba0 commit f531258
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ There are at least the following options to integrate the formatting in IntelliJ
1. Manually run the Gradle task `spotlessApply` in the root project from the UI to format all files
2. Automatically run `spotlessApply` before building (right click on Gradle task in UI, select respective option)
3. Add the call to Gradle as external tool and assign a key binding (Settings -> Tools -> External tools; Settings -> Keymap)
4. Add a file watcher (requires file watchers plugin) to run spotless for individual changed files (Note: individual runs take relatively long due to the Gradle configuration phase)
4. Add a file watcher (requires file watchers plugin) to run spotless for individual changed files

## License

Expand Down
10 changes: 6 additions & 4 deletions spotless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
# Advantage over calling Gradle for a single file directly is identifying a subproject and only running the task there.
# Also, Gradle is only run for certain file extensions (in case this can't bbe filtered easily when calling the script)
#
# Note: Sadly we can't avoid the Gradle configuration phase which takes relatively long due to the big number of subprojects.
# We can't avoid the Gradle configuration phase which takes relatively long due to the big number of subprojects,
# But when targeting individual projects we can speed up the process using the on-demand configuration feature
# (see https://docs.gradle.org/current/userguide/multi_project_configuration_and_execution.html).
#
# Configuration as file watcher in IntelliJ:
#
Expand All @@ -31,7 +33,7 @@ allowed_extensions=("java" "md" "groovy" "gradle")
if [ -z "$1" ]; then
echo "No file path provided"

exec ./gradlew spotlessApply
exec ./gradlew spotlessApply --parallel
exit 0
fi

Expand Down Expand Up @@ -63,13 +65,13 @@ while [ "$current_dir" != "/" ]; do
if [ "$current_dir" == "$script_dir" ]; then
echo "Found build.gradle in the project root: $relative_path"

exec ./gradlew spotlessApply "-PspotlessIdeHook=$file_path" --parallel
exec ./gradlew :spotlessApply "-PspotlessIdeHook=$file_path" --parallel --configure-on-demand
else
# Replace / with : in the relative path
formatted_path=$(echo "$relative_path" | tr '/' ':')
echo "Found build.gradle in a subfolder: $formatted_path"

exec ./gradlew ":$formatted_path:spotlessApply" "-PspotlessIdeHook=$file_path" --parallel
exec ./gradlew ":$formatted_path:spotlessApply" "-PspotlessIdeHook=$file_path" --parallel --configure-on-demand
fi
exit 0
fi
Expand Down

0 comments on commit f531258

Please sign in to comment.