Skip to content

Compiler options should be possible to be set with -D without pom.xml -A mapping #275

Description

@AndreasIgel

Summary

All simple-builders compiler options (e.g. skipFormatting, generateJavaDoc, builderAccess, verbose) require a corresponding -Asimplebuilder.<option>=${simplebuilder.<option>} entry in the project's pom.xml <compilerArgs> section to reach the annotation processor. Setting -Dsimplebuilder.<option>=<value> on the Maven command line alone has no effect, because the annotation processor reads from processingEnv.getOptions() (which only receives -A prefixed args), not from JVM system properties.

The documentation at docs/CONFIGURATION.md and docs/DEBUG_LOGGING.md suggests that mvn compile -Dsimplebuilder.skipFormatting=true works, but this is only true for projects that already have the matching -A mapping in their pom.xml. Users who follow the documentation without adding the mapping will find the option silently ignored.

Steps to reproduce

  1. In any project using simple-builders, run:
    mvn clean compile -Dsimplebuilder.generateJavaDoc=DISABLED
  2. Check the generated builder source — javadoc is still present, the option had no effect.

Expected behaviour

-Dsimplebuilder.<option>=<value> on the command line should work without requiring additional pom.xml configuration, so users can easily test and toggle options from the console.

Proposed solution

Add a System.getProperty() fallback in CompilerArgumentsReader.readValue() so that JVM system properties (-D) are checked when the -A compiler arg is not present:

public String readValue(CompilerArgumentsEnum argument) {
    // 1. Try -A compiler arg (highest priority)
    String value = processingEnv.getOptions().get(argument.getCompilerArgument());
    if (value == null) {
        value = processingEnv.getOptions().get(argument.getOptionName());
    }
    // 2. Fallback: check JVM system property (-D on command line)
    if (value == null) {
        value = System.getProperty(argument.getCompilerArgument());
    }
    return value;
}

This establishes a clear priority chain:

  1. Annotation values (@SimpleBuilder.Options) — highest priority
  2. -A compiler args — medium priority (explicit, pom-configured)
  3. -D system properties — fallback (command-line convenience)
  4. Defaults — lowest priority

The -A path remains the canonical mechanism (as documented for Maven/Gradle/IntelliJ), while -D becomes a zero-config convenience for command-line usage.

Affected files

  • processor/src/main/java/org/javahelpers/simple/builders/processor/processing/CompilerArgumentsReader.java — add system property fallback
  • docs/CONFIGURATION.md — clarify that -D works as a fallback (no pom.xml change required)
  • docs/DEBUG_LOGGING.md — already documents the -A requirement; update to mention -D also works

Impact

  • No breaking changes — existing -A mappings continue to take priority
  • Improved UX — all options work from command line out of the box
  • Documentation becomes accuratemvn compile -Dsimplebuilder.skipFormatting=true works as documented

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions