Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradle: excluding spotlessJava should also exclude spotlessApply #2097

Open
tkruse opened this issue Apr 15, 2024 · 0 comments
Open

gradle: excluding spotlessJava should also exclude spotlessApply #2097

tkruse opened this issue Apr 15, 2024 · 0 comments
Labels

Comments

@tkruse
Copy link

tkruse commented Apr 15, 2024

When running gradle compileJava -xspotlessJava, spotlessApply will still run. Since spotlessApply copies files from build/spotless/spotlessJava to the source tree, this can overwrite unsaved work in progress, making teams lose valuable work due to a simple misunderstanding. Since this is a silent overwrite, team might also not notice that changes have been made, allowing bugs to enter the codebase.

spotlessApply should only ever run when the files it copies were created as part of the same build, to ensure no work is lost.

This happened on a company project, so I cannot quickly produce a public repo, but I could if need be. The steps to reproduce would be (in a java project using the spotless plugin...):

git clone ...
cd ...
// assuming this will have some file that can be formatted
 ./gradlew compileJava
  git reset --hard
  git checkout other_branch
  // assuming some file from earlier branch is different here
  
  ./gradlew compileJava -xspotlessJava
  git diff

The last git diff should not have any changes. However, currently for me this overwrites the source file with the spotless output from the ./gradlew compileJava task.

Using gradle8, java17, spotless 6.25.0 on MacOs.

@nedtwigg nedtwigg added the bug label Apr 15, 2024
@nedtwigg nedtwigg changed the title excluding spotlessJava should also exclude spotlessApply gradle: excluding spotlessJava should also exclude spotlessApply Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants