Skip to content

Support -D system properties for compiler options (#275) - #287

Merged
AndreasIgel merged 17 commits into
java-helpers:mainfrom
AndreasIgel:devin/1788590630-sysprop-fallback-275
Sep 12, 2026
Merged

AndreasIgel merged 17 commits into
java-helpers:mainfrom
AndreasIgel:devin/1788590630-sysprop-fallback-275

Conversation

@AndreasIgel

Copy link
Copy Markdown
Collaborator

Summary

mvn compile -Dsimplebuilder.<option>=<value> (and the Gradle equivalent) now works without a -Asimplebuilder.<option>=${simplebuilder.<option>} mapping in the build file. Previously the docs suggested it did, but the processor only read processingEnv.getOptions() (i.e. -A args), so -D alone was silently ignored (#275).

CompilerArgumentsReader.readValue now resolves:

value = System.getProperty("simplebuilder.<opt>");   // -D  (new, highest)
if (value == null) value = options.get("simplebuilder.<opt>");  // -A, prefixed
if (value == null) value = options.get("<opt>");                // -A, bare (legacy)

The system property is checked first: -A args from pom.xml/build.gradle and from the CLI land in the same javac option map, so a -D given on the command line would otherwise never be able to override a setting configured in the build file. Only the prefixed name is looked up as a system property — a bare -Dverbose=true is deliberately ignored to avoid colliding with unrelated JVM properties. Since every option goes through readValue, this covers all of readBuilderConfiguration, verbose, performanceTracking* and deactivateGenerationComponents at once.

Effective precedence: @SimpleBuilder.Options > -D system property > -A compiler arg > default.

Verified end-to-end (not committed): Maven mvn -pl example clean compile -D… changes the generated builders; Gradle 8.10 with the default in-process compiler (-D… on the CLI or systemProp.simplebuilder.… in gradle.properties) does too. It does not work with forked javac (<fork>true</fork> / options.fork = true) or IDE builds — -A remains required there — and Gradle does not treat the property as a task input (compileJava stays UP-TO-DATE without clean/--rerun-tasks). All of this is documented in docs/CONFIGURATION.md / docs/DEBUG_LOGGING.md.

Tests: three CompilerArgumentsReaderTest cases (fallback, -D wins over -A, bare-name property ignored).

Closes #275.

AndreasIgel and others added 17 commits August 15, 2026 10:57
The class-level Javadoc and docs/CONFIGURATION.md implied that
@SimpleBuilder is inherited by subclasses, but the annotation was not
meta-annotated with @inherited. As a result BuilderProcessor, which
collects types via RoundEnvironment.getElementsAnnotatedWith(...),
only produced builders for the exact type carrying @SimpleBuilder and
not for unannotated subclasses.

Add @inherited to @SimpleBuilder so subclasses are treated as if they
also carried the annotation, mirroring the existing behaviour of
@SimpleBuilder.Template (which is already @inherited). Update the
Javadoc to document the inheritance explicitly and clarify the
CONFIGURATION.md wording. @Ignore4BuilderGeneration still suppresses
generation for the exact type it is placed on, so opt-outs continue
to work as before.

Add SimpleBuilderInheritanceTest covering direct inheritance, the
opt-out interaction, and multi-level (grandchild) inheritance.

Closes java-helpers#244

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ance

Rename SimpleBuilderInheritanceTest to BuilderAnnotationInheritanceTest
so the name reflects that it covers both builder-triggering annotations.
Add unannotatedSubclassGetsBuilderFromInheritedTemplate, which verifies
that a custom @inherited template annotation (meta-annotated with
@SimpleBuilder.Template) propagates to unannotated subclasses, matching
the existing behaviour of @SimpleBuilder itself.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The Template Javadoc and CONFIGURATION.md "Template Annotations" section
did not explain that @SimpleBuilder.Template is @inherited, nor that a
custom template annotation must additionally declare @inherited to
propagate to unannotated subclasses. Add explicit documentation and an
example showing the @inherited custom annotation pattern.

Also move assertNoBuilderGenerated to ProcessorAsserts so it is shared
by BuilderAnnotationInheritanceTest and Ignore4BuilderGenerationTest
instead of being duplicated as a private helper in each test class.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
While @SimpleBuilder and @inherited template annotations now correctly
trigger builder generation for unannotated subclasses, the configuration
options declared on the parent's @SimpleBuilder(options = ...) or template
are not yet applied to inherited subclass builders — they use default
options instead. This is tracked separately in issue java-helpers#245.

Add caveats to the SimpleBuilder Javadoc, the CONFIGURATION.md Template
Annotations section, and the Template Annotations Not Working
troubleshooting section so users are not surprised by this limitation.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Add explicit guidance that @SimpleBuilder.Template is a meta-annotation
for custom annotation declarations (@interface) only and cannot be
placed directly on a class or record. @SimpleBuilder is for direct
one-off annotation of classes/records.

- SimpleBuilder.java: add 'When to use' section to class-level Javadoc
- SimpleBuilder.Template Javadoc: state it can only be placed on
  annotation types (ANNOTATION_TYPE), not on classes/records
- CONFIGURATION.md 'Template Annotations': add comparison table and
  introductory paragraph
- CONFIGURATION.md troubleshooting: add item about @SimpleBuilder.Template
  not being a class annotation

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…Javadoc

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…arget

The compiler and IDE already enforce @target(ANNOTATION_TYPE) and show
a clear error when @SimpleBuilder.Template is placed on a class/record,
so this troubleshooting item adds no value.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…lpers#275)

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
…ers#275)

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@AndreasIgel
AndreasIgel merged commit 8fced90 into java-helpers:main Sep 12, 2026
6 checks passed
@AndreasIgel
AndreasIgel deleted the devin/1788590630-sysprop-fallback-275 branch September 12, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant