Skip to content

Commit 7294df5

Browse files
committed
Add checkstyle enforcement to build and CI
- Add maven-checkstyle-plugin (3.6.0, Checkstyle 10.23.1) to pluginManagement - Configure google_checks.xml with suppressions, fail on warnings - Run checkstyle:check in Java 17+ profile (verify phase) - Add checkstyle step to CI format job - Add check-style Makefile target - Replace spotbugs-annotations with jsr305 (for javax.annotation.Nullable)
1 parent 916b5dc commit 7294df5

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
- name: Check formatting (Google Java Style)
2424
run: mvn --batch-mode fmt:check
2525

26+
- name: Check style (Google Java Style)
27+
run: mvn --batch-mode checkstyle:check
28+
2629
test:
2730
runs-on: ubuntu-latest
2831
strategy:

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ help:
77
@echo " make compile - Run clean compile on all supported JDKs ($(JDK_VERSIONS))"
88
@echo " make format - Auto-format code (Google Java Style)"
99
@echo " make check-format - Check code formatting (Google Java Style)"
10+
@echo " make check-style - Run checkstyle (Google Java Style)"
1011
@echo " make examples - Regenerate EXAMPLES.md and README.md from test source code"
1112
@echo " make check-examples - Verify EXAMPLES.md and README.md are up to date"
1213
@echo " make version - Show current project version"
@@ -73,6 +74,10 @@ format:
7374
check-format:
7475
mvn fmt:check
7576

77+
.PHONY: check-style
78+
check-style:
79+
mvn checkstyle:check
80+
7681
.PHONY: examples
7782
examples:
7883
python3 tools/generate_examples.py

pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,25 @@
284284
<artifactId>fmt-maven-plugin</artifactId>
285285
<version>2.29</version>
286286
</plugin>
287+
<plugin>
288+
<groupId>org.apache.maven.plugins</groupId>
289+
<artifactId>maven-checkstyle-plugin</artifactId>
290+
<version>3.6.0</version>
291+
<dependencies>
292+
<dependency>
293+
<groupId>com.puppycrawl.tools</groupId>
294+
<artifactId>checkstyle</artifactId>
295+
<version>10.23.1</version>
296+
</dependency>
297+
</dependencies>
298+
<configuration>
299+
<configLocation>google_checks.xml</configLocation>
300+
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
301+
<violationSeverity>warning</violationSeverity>
302+
<failOnViolation>true</failOnViolation>
303+
<consoleOutput>true</consoleOutput>
304+
</configuration>
305+
</plugin>
287306
<plugin>
288307
<groupId>org.apache.maven.plugins</groupId>
289308
<artifactId>maven-enforcer-plugin</artifactId>
@@ -525,6 +544,19 @@
525544
</execution>
526545
</executions>
527546
</plugin>
547+
<plugin>
548+
<groupId>org.apache.maven.plugins</groupId>
549+
<artifactId>maven-checkstyle-plugin</artifactId>
550+
<executions>
551+
<execution>
552+
<id>checkstyle</id>
553+
<phase>verify</phase>
554+
<goals>
555+
<goal>check</goal>
556+
</goals>
557+
</execution>
558+
</executions>
559+
</plugin>
528560
</plugins>
529561
</build>
530562
</profile>

0 commit comments

Comments
 (0)