Java Code Quality Detection

September 22, 2025 · View on GitHub

Toolchain

Formatting Tools

  • Spotless: Automatic formatting based on Google Java Format
  • Maven Integration: Implemented through spotless-maven-plugin

Quality Detection Tools

  • Checkstyle: Code style validation (Google Java Style Guide)
  • SpotBugs: Static analysis and bug detection
  • PMD: Code quality analysis and complexity control

Makefile Integration

Unified Commands

make format    # Format all languages (including Java)
make check     # Check all language quality (including Java)

Java-specific Commands

make fmt-java              # Format Java code
make check-java            # Java quality check
make test-java             # Run Java tests
make build-java            # Build Java project

Tool Installation

make install-tools-java    # Install Java development tools
make check-tools-java      # Check Java tool status

Quality Standards

Check ItemStandardTool
Code FormatGoogle Java FormatSpotless
Code StyleGoogle Java Style GuideCheckstyle
Line Length≤120 charactersCheckstyle
Cyclomatic ComplexityFunction ≤10, Class ≤40PMD
Method Length≤50 linesPMD
Parameter Count≤7 parametersPMD
Class Length≤500 linesPMD
Static Analysis0 issuesSpotBugs

Common Issues

Formatting Issues

make fmt-java  # Auto-fix format issues
# Internal execution: mvn spotless:apply

Style Check Issues

make check-java  # Run all quality checks
# Internal execution: mvn checkstyle:check pmd:check spotbugs:check

Complexity Issues

# PMD will detect overly complex methods
# Need to refactor methods with complexity >10

Static Analysis Issues

# SpotBugs will detect potential bugs
# Fix code according to report suggestions

Configuration Files

Maven Plugin Configuration (pom.xml)

<properties>
    <spotless.version>2.43.0</spotless.version>
    <checkstyle.version>3.3.1</checkstyle.version>
    <spotbugs.version>4.8.2.0</spotbugs.version>
    <pmd.version>3.21.2</pmd.version>
</properties>

Checkstyle Configuration (checkstyle.xml)

<module name="Checker">
    <module name="TreeWalker">
        <module name="LineLength">
            <property name="max" value="120"/>
        </module>
        <module name="CyclomaticComplexity">
            <property name="max" value="10"/>
        </module>
    </module>
</module>