Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ jobs:
# --info: For now, we'll generate lots of logs while setting up the GH Actions
# --scan: Publish the build scan. This will only work on PRs from apache/kafka and trunk
# --no-scan: For public fork PRs, we won't attempt to publish the scan
run: |
./gradlew --build-cache --info $SCAN_ARG check releaseTarGz -x test
run: ./gradlew --build-cache --info $SCAN_ARG check releaseTarGz -x test
- name: Sanity Check
run: ./gradlew --build-cache rewriteDryRun
- name: Archive check reports
if: always()
uses: actions/upload-artifact@v4
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ The import order is a part of static check. please call `spotlessApply` to optim

./gradlew spotlessApply

#### Rewrite
The build system incorporates [Moderne](https://moderne.io/) rewrite capabilities for automated code transformations.
Copy link
Member

@mjsax mjsax Jan 8, 2026

Choose a reason for hiding this comment

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

No idea what "Moderne" is. Do we want to depend on it? \cc @ijuma @chia7712

In general, I am a big supported to add checks and fail the build if we detect issue. but "automated code transformations" sounds not desirable to me personally

Copy link
Author

@Pankraz76 Pankraz76 Jan 9, 2026

Choose a reason for hiding this comment

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

Actually, it's not fully automated—it just fails the build when it detects problematic code, which is exactly what everyone wants to see.

Just like Error Prone offers patching, Rewrite does too. That's a good thing, because it saves time on trivial fixes that the tool can handle automatically.

Still, it's up to each developer to apply and verify the changes themselves. It's simply an optional tool (run), not a requirement.

As long as the code is complain in the end, Rewrite is satisfied. How you get there is up to each individual.

sounds not desirable to me personally

Also im wondering about this argument in the presents of spotless. This tool is all about automating stuff and patching. So its actually nothing new, just covers the most issues as well, but can got beyond as well, making it some consideration.


- **Convention** (e.g., JUnit's naming rules)
- **Refactor** safely (e.g., rename methods, migrate APIs)
- **Modernize** (e.g., Java 8 → Java 17 features)
- **Patterns** (e.g., replace `Vector` with `ArrayList`)

`./gradlew rewriteDryRun`

#### Spotbugs ####
Spotbugs uses static analysis to look for bugs in the code.
You can run spotbugs using:
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ plugins {

id "com.github.spotbugs" version '6.4.4' apply false
id 'org.scoverage' version '8.1' apply false
id 'org.openrewrite.rewrite' version '7.22.0' apply false
id 'com.gradleup.shadow' version '8.3.9' apply false
id 'com.diffplug.spotless' version "8.0.0"
}

apply from: "$rootDir/gradle/rewrite.gradle"

ext {
minClientJavaVersion = 11
minNonClientJavaVersion = 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ public static ShareAcknowledgeResponse parse(Readable readable, short version) {
);
}

private static boolean matchingTopic(ShareAcknowledgeResponseData.ShareAcknowledgeTopicResponse previousTopic, TopicIdPartition currentTopic) {
if (previousTopic == null)
return false;
return previousTopic.topicId().equals(currentTopic.topicId());
}

public static ShareAcknowledgeResponseData.PartitionData partitionResponse(TopicIdPartition topicIdPartition, Errors error) {
return partitionResponse(topicIdPartition.topicPartition().partition(), error);
}
Expand Down
30 changes: 30 additions & 0 deletions config/sanity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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
#
# http://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.
---
type: specs.openrewrite.org/v1beta/recipe
name: org.apache.kafka.openrewrite.SanityCheck
displayName: Apply all common best practices
description: Comprehensive code quality recipe combining modernization, security, and best practices.
recipeList:
- org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods
# - org.openrewrite.staticanalysis.CommonStaticAnalysis # composition for -> NoDoubleBraceInitialization
# - org.openrewrite.staticanalysis.EqualsAvoidsNull
# - org.openrewrite.staticanalysis.InlineVariable
# - org.openrewrite.staticanalysis.NoDoubleBraceInitialization
Copy link
Author

Choose a reason for hiding this comment

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

also this could be handled next as also encountered in:

@mjsax

# - tech.picnic.errorprone.refasterrules.EqualityRulesRecipes
# - tech.picnic.errorprone.refasterrules.NullRulesRecipes
# - tech.picnic.errorprone.refasterrules.StringRulesRecipes
# - tech.picnic.errorprone.refasterrules.TimeRulesRecipes
---
29 changes: 29 additions & 0 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

apply plugin: 'org.openrewrite.rewrite'

dependencies {
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.23.0')
}

rewrite {
activeRecipe('org.apache.kafka.openrewrite.SanityCheck')
configFile = project.getRootProject().file("${rootDir}/config/sanity.yml")
setExportDatatables(true)
setFailOnDryRunResults(true)
}