Skip to content

Add Gradle tasks and Git hooks for IntelliJ-based code formatting (#15535) - #15555

Merged
jdaugherty merged 12 commits into
apache:7.0.xfrom
sanjana2505006:feat/intellij-formatter-15535
Jun 30, 2026
Merged

Add Gradle tasks and Git hooks for IntelliJ-based code formatting (#15535)#15555
jdaugherty merged 12 commits into
apache:7.0.xfrom
sanjana2505006:feat/intellij-formatter-15535

Conversation

@sanjana2505006

@sanjana2505006 sanjana2505006 commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Added a formatCode Gradle task that uses the IntelliJ CLI formatter to keep our code style consistent. I also added an installGitHooks task that sets up a git pre-commit hook to automatically format staged files. This should help avoid formatting issues during review. Fixes #15535.

@jdaugherty

Copy link
Copy Markdown
Contributor

@sanjana2505006 we explicitly decided to not auto-install the hook so it would be optional if people wanted it.

Comment thread build.gradle Outdated
@bito-code-review

Copy link
Copy Markdown

To revert the changes in build.gradle, remove the added plugin block and revert the lambda expressions in the ext block back to method references.

build.gradle

/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    https://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

import java.time.Instant
import java.time.LocalDate
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import org.apache.tools.ant.taskdefs.condition.Os
ext {
    isReproducibleBuild = System.getenv("SOURCE_DATE_EPOCH") != null
    buildInstant = java.util.Optional.ofNullable(System.getenv("SOURCE_DATE_EPOCH"))
            .filter(s -> !s.isEmpty())
            .map(Long::parseLong)
            .map(Instant::ofEpochSecond)
            .orElseGet(Instant::now)

private static void doNotApplyStylingToTests(Project project) {
project.tasks.named('checkstyleTest') {
it.enabled = false // Do not check test sources at this time
if (project.tasks.names.contains('checkstyleTest')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why this change was necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally added this to focus the initial rollout on production source code and avoid overwhelming the PR with style violations from the existing test suite. However, I agree that tests should ideally follow the same standards. Would you prefer that I remove this block and enable styling for tests as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we do need to eventually format our tests, we have agreed to not do so at this time. We should leave styles and only adjust the styles when working on the tests.

throw new RuntimeException("IntelliJ code style settings not found at ${settingsFile.absolutePath}")
}

project.exec { ExecSpec exec ->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the publishAllToMavenLocal task for how to do in this a modern Gradle way without referencing project .

@sanjana2505006

Copy link
Copy Markdown
Contributor Author

To revert the changes in build.gradle, remove the added plugin block and revert the lambda expressions in the ext block back to method references.

build.gradle

/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    https://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

import java.time.Instant
import java.time.LocalDate
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import org.apache.tools.ant.taskdefs.condition.Os
ext {
    isReproducibleBuild = System.getenv("SOURCE_DATE_EPOCH") != null
    buildInstant = java.util.Optional.ofNullable(System.getenv("SOURCE_DATE_EPOCH"))
            .filter(s -> !s.isEmpty())
            .map(Long::parseLong)
            .map(Instant::ofEpochSecond)
            .orElseGet(Instant::now)

I have reverted the buildInstant calculation to use the original method references and removed the extra filter. I am keeping the plugin application at the root level so that the new formatting tasks remain available for use.

@sanjana2505006
sanjana2505006 force-pushed the feat/intellij-formatter-15535 branch from 7f21945 to 0ca94f3 Compare April 11, 2026 19:13

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@borinquenkid Can you please take a look at this as well? I think this is very close to being mergeable.

}
}

private static void doNotApplyStylingToTests(Project project) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to stay. We decided as a project to not yet do styling changes to the tests.

@jdaugherty

Copy link
Copy Markdown
Contributor

@sanjana2505006 if you can get the rest of these comments implemented, I'll ping another reviewer and we can get this merged.

@sanjana2505006
sanjana2505006 force-pushed the feat/intellij-formatter-15535 branch 2 times, most recently from 5251fb7 to 2322979 Compare April 22, 2026 19:57
@sanjana2505006

Copy link
Copy Markdown
Contributor Author

@sanjana2505006 if you can get the rest of these comments implemented, I'll ping another reviewer and we can get this merged.

Done, please have a look and let me know if there's anything I need to update.

Comment thread build.gradle
ext {
isReproducibleBuild = System.getenv("SOURCE_DATE_EPOCH") != null
buildInstant = java.util.Optional.ofNullable(System.getenv("SOURCE_DATE_EPOCH"))
.filter(s -> !s.isEmpty())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanjana2505006 this should not be removed.

@sanjana2505006
sanjana2505006 force-pushed the feat/intellij-formatter-15535 branch from 769f735 to ae7d7d1 Compare April 23, 2026 14:21
@jdaugherty
jdaugherty requested a review from matrei May 4, 2026 04:42
@jdaugherty

Copy link
Copy Markdown
Contributor

@matrei this looks accepatble to me. Do you agree? If so, we can merge.

Comment thread build-logic/plugins/build.gradle Outdated
Comment thread build-logic/plugins/build.gradle Outdated
Comment thread build-logic/plugins/build.gradle Outdated
@jdaugherty jdaugherty mentioned this pull request May 6, 2026
@jdaugherty

Copy link
Copy Markdown
Contributor

@sanjana2505006 Can you please take a look at @matrei feedback so we can get this merged?

@jdaugherty

Copy link
Copy Markdown
Contributor

@matrei this feedback is complete, can you please confirm it's ok to merge?

@jdaugherty

Copy link
Copy Markdown
Contributor

@matrei hold off. there's a problem - the format.sh / format bat is the correct way to invoke this. The jetbrains toolbox installs an idea but it assumes it's not running / will only return once the app is closed. I'm going to rework this.

@jdaugherty

Copy link
Copy Markdown
Contributor

@matrei this should be fixed now. You should be able to invoke the formatting independently of intellij running.

@testlens-app

testlens-app Bot commented Jun 30, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: bb41c25
▶️ Tests: 25131 executed
⚪️ Checks: 33/33 completed


Learn more about TestLens at testlens.app.

jdaugherty and others added 6 commits June 30, 2026 18:06
Co-authored-by: Mattias Reichel <mattias.reichel@gmail.com>
Co-authored-by: Mattias Reichel <mattias.reichel@gmail.com>
Co-authored-by: Mattias Reichel <mattias.reichel@gmail.com>
Co-authored-by: Mattias Reichel <mattias.reichel@gmail.com>
@jdaugherty
jdaugherty merged commit 4cc6dde into apache:7.0.x Jun 30, 2026
@sanjana2505006
sanjana2505006 deleted the feat/intellij-formatter-15535 branch July 25, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add gradle tasks to assist in code formatting

3 participants