-
Notifications
You must be signed in to change notification settings - Fork 8.8k
optimize: Apply Spotless with Palantir Java Format #7223
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
Changes from all commits
32a5e7e
de6cf2e
73b865c
c294714
32b55f7
661d18a
f7a0266
fc7770f
3d5b4eb
5c30142
3bee817
a31ddf8
4f07580
0e71c8d
ffa856b
0b3d1e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,6 +289,78 @@ | |
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<!-- profile: spotless --> | ||
<profile> | ||
<id>jdk9-jdk11-spotless</id> | ||
<activation> | ||
<jdk>[1.8, 11)</jdk> | ||
</activation> | ||
<properties> | ||
<palantirJavaFormat.version>1.1.0</palantirJavaFormat.version> | ||
</properties> | ||
</profile> | ||
|
||
<profile> | ||
<id>jdk11-jdk21-spotless</id> | ||
<activation> | ||
<jdk>[11, 21)</jdk> | ||
</activation> | ||
<properties> | ||
<palantirJavaFormat.version>2.28.0</palantirJavaFormat.version> | ||
</properties> | ||
</profile> | ||
|
||
<profile> | ||
<id>jdk21-spotless</id> | ||
<activation> | ||
<jdk>[21,)</jdk> | ||
</activation> | ||
<properties> | ||
<palantirJavaFormat.version>2.39.0</palantirJavaFormat.version> | ||
</properties> | ||
</profile> | ||
<profile> | ||
<id>java11+</id> | ||
<activation> | ||
<jdk>[11,)</jdk> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.diffplug.spotless</groupId> | ||
<artifactId>spotless-maven-plugin</artifactId> | ||
<version>${spotless-maven-plugin.version}</version> | ||
<configuration> | ||
<java> | ||
<excludes> | ||
<exclude>**/script/**</exclude> | ||
<exclude>**/generated/**</exclude> | ||
<exclude>**/antlr/mysql/parser/*.*</exclude> | ||
<exclude>**/antlr/mysql/antlr/*.*</exclude> | ||
<exclude>**/antlr/mysql/stream/ANTLRNoCaseStringStream.java</exclude> | ||
</excludes> | ||
<ratchetFrom>HEAD</ratchetFrom> | ||
<palantirJavaFormat> | ||
<version>${palantirJavaFormat.version}</version> | ||
</palantirJavaFormat> | ||
<removeUnusedImports/> | ||
<trimTrailingWhitespace/> | ||
<endWithNewline/> | ||
</java> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How it works in github action workflow, I didn't see this profile id included in workflow.In addition to checking if the format is as expected, is it possible to automatically format changes in the workflow and commit them to PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work in GitHub Actions. Automatically formatting and committing changes seems more suitable for a For now, in this PR, I’ve applied There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. |
||
<goal>apply</goal> | ||
</goals> | ||
<phase>process-sources</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
<build> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slievrly @funky-eyes @xingfudeshi
I configured
<ratchetFrom>HEAD</ratchetFrom>
so that only the modified files are formatted by comparing them with the currently checked-out commit (HEAD).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! I will pull this PR to my local machine for related testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@funky-eyes
Currently, our baseline is set to
HEAD
, which means that only files changed since the last commit are considered. This creates a potential issue: if code with incorrect formatting gets committed,checkstyle
will catch it, butSpotless
won’t apply its fixes, and we lose the intended benefit.To address this, we tried switching the baseline from HEAD to
origin/2.x
. However, the branch wasn’t recognized. 🥹What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I pulled your code and followed the steps. Seems to work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can be done this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, unless we format and commit all the code at once, we will not be able to prompt the user to run
mvn spotless:apply
. What if we change theHEAD
to2.x
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is a good one.
However, when I tried running it locally, the behavior was different from what I expected, so I'm reconsidering it.
To explain in more detail, switching to
origin/2.x
should apply changes only to the files that have been modified from2.x
.Even though there were no changes in my local branch, some recently committed files in

2.x
were also modified.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, I think setting it to
2.x
is a better approach than setting it toHEAD
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this commit 4f07580 i changed ratchet from to origin/2.x
Then below error occured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that after setting it to 2.x, the number of changed files is quite large, unless we are willing to accept changes to all files. Otherwise, I think we can initially set it to HEAD, merge this PR, and then create an issue to discuss the remaining problems.
@slievrly What do you think?