Skip to content

Latest commit

 

History

History
73 lines (60 loc) · 2.57 KB

File metadata and controls

73 lines (60 loc) · 2.57 KB

Test Formatter — Maven usage notes

This project is set up with the Spotless formatter and Maven Toolchains. Below are quick instructions to format code and configure Java toolchains.

Run Spotless (code formatter)

Common commands:

  • Check formatting (fails build on violations): mvn spotless:check
  • Apply formatting fixes: mvn spotless:apply

Notes:

  • Spotless is also bound to the verify phase to run spotless:check automatically.
  • The current configuration formats Java sources under src/main/java using Palantir Java Format (see pom.xml).

Configure Maven Toolchains

This project uses the Maven Toolchains Plugin so you can build with specific JDKs without changing your system default.

  1. Create or edit your Maven toolchains file at:
  • macOS/Linux: ~/.m2/toolchains.xml
  • Windows: %USERPROFILE%.m2\toolchains.xml
  1. Paste your toolchain definitions. Example:
<?xml version="1.0" encoding="UTF-8"?>
<toolchains>
    <!-- JDK toolchains -->
    <toolchain>
        <type>jdk</type>
        <provides>
            <version>1.8</version>
            <vendor>liberica</vendor>
        </provides>
        <configuration>
            <jdkHome>/Users/your-username/.local/share/mise/installs/java/liberica-8u462+11</jdkHome>
        </configuration>
    </toolchain>
    <toolchain>
        <type>jdk</type>
        <provides>
            <version>21</version>
            <vendor>liberica</vendor>
        </provides>
        <configuration>
            <jdkHome>/Users/your-username/.local/share/mise/installs/java/liberica-21.0.8+12</jdkHome>
        </configuration>
    </toolchain>
</toolchains>
  1. How it ties into this project:
  • pom.xml configures the Maven Toolchains Plugin to select a Liberica JDK 1.8 for compilation.
  • The Maven Compiler Plugin uses release 8 to compile against Java 8 APIs.
  1. Verify toolchain selection
  • Show toolchain resolution details: mvn -X -ntp -V validate (Look for "Required toolchain: jdk [ vendor='liberica' version='1.8' ]" and the resolved jdkHome.)
  • Print active Java during build (optional): mvn -q --version

Quick start

  • Format code: mvn spotless:apply
  • Check formatting in CI: mvn -B -ntp verify
  • Full build from scratch: mvn -B -ntp clean verify

Troubleshooting

  • If Maven cannot find the requested toolchain, ensure the vendor and version in toolchains.xml match those in pom.xml (this project expects vendor liberica and version 1.8).
  • Confirm the jdkHome paths exist and point to valid JDK installations (not a JRE).
  • You can install additional JDKs and add them to toolchains.xml as shown above.