dongjinleekr opened a new pull request #10428: URL: https://github.com/apache/kafka/pull/10428
This PR is a part of [KAFKA-10787](https://issues.apache.org/jira/browse/KAFKA-10787) umbrella task, replacing the previous implementation [here](https://github.com/apache/kafka/pull/8404/). **In short, it applies automatic import ordering and checking to the `core` module.** Here are some backgrounds. When I first started [KAFKA-10787](https://issues.apache.org/jira/browse/KAFKA-10787), I thought it is a trivial one and can be resolved with only one PR. But it is entirely wrong. 1. It modifies hundreds of files; it is not only hard to review but also, every time it has some code conflict with the trunk branch. 2. As @mjsax already pointed out, the previous implementation omits the essential way of solving this problem - **automatic import formatter**. Since it includes the checkstyle rules only, it shows error messages for the import ordering violation and that's it. For the reasons above, it is almost impossible to resolve this issue with one commit or PR. So, I restarted this feature from scratch. First of all, I changed the approach like following: 1. Take an incremental approach, i.e., enlarge the import ordering rules applied area gradually. (In other words, narrow down the exception area to the import ordering rules, step by step.) 2. By adopting automatic code formatter, make the build tool to apply the import order automatically. This approach has the advantages like: 1. We can apply the import order step by step; it is feasible to review and greatly reduces the possibility of code conflict. 2. The dev team doesn't have to care about the formatting anymore; the build tool automatically take cares of it. With this scheme, we can expand the scope of auto-formatting and checkstyle incrementally. In turn, I converted [KAFKA-10787](https://issues.apache.org/jira/browse/KAFKA-10787) into an umbrella one. As the first subtask, this PR do the following: 1. Define the import ordering rule in checkstyle: `kafka`, `org.apache.kafka`, `com`, `net`, `org`, `java`, `javax` and static imports. It is identical to [what we discussed in the dev mailing list](https://lists.apache.org/thread.html/rf6f49c845a3d48efe8a91916c8fbaddb76da17742eef06798fc5b24d%40%3Cdev.kafka.apache.org%3E), except each package is grouped independely. (e.g., `kafka` and `org.apache.kafka` are regarded as independent groups.) 2. Add an eclipse formatter file, which includes: - Minimal formatting rules that follow current checkstyle rules. - `ImportOrder` rule for the newly introduced import ordering rule. 3. **Add a spotless configuration to reformat the subset of modules automatically.** (as of present, `core` module only.) 4. Apply import ordering rule to `core` module with the automatic formatter. Here are some reasons for the decisions I made: 1. Why choose eclipse formatter? As all of you know, Apache Kafka is using gradle as its build tool. To automatically apply the import ordering rule with gradle, we have to use [spotless](https://github.com/diffplug/spotless), which supports two formatters - google formatter and eclipse formatter. If we choose google formatter, it changes not only import ordering but also the other aspects of code, like an indentation. To minimize non-import ordering modifications, I choose eclipse formatter, which supports a custom formatter configuration. As you can see here, the formatter defines a minimal rules for out code only. 2. The original proposal consists of 3 groups: `kafka`/`org.apache.kafka`, `com`/`org`/`net`, `java`/`javax`, and static imports. Why are those packages separated into independent groups? It's simple - the spotless automatic formatter doesn't allow packages with different prefixes into one group. So I separated them. ### Committer Checklist (excluded from commit message) - [ ] Verify design and implementation - [ ] Verify test coverage and CI build status - [ ] Verify documentation (including upgrade notes) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org