Skip to content

Add a built-in minimal builder template annotation, e.g. @SimpleMinimalBuilder, that generates the smallest possible builder by disabling all optional features. #257

Description

@AndreasIgel

Motivation

Right now, tests and users that want a "minimal" builder must create a custom template and explicitly disable every optional feature. A dedicated built-in @SimpleMinimalBuilder annotation would make this common use-case a one-liner and give the project a canonical example of a template-based builder preset.

Proposed Solution

Introduce a new public annotation in core:

@SimpleBuilder.Template(options = @SimpleBuilder.Options(
    generateFieldSupplier = OptionState.DISABLED,
    generateFieldConsumer = OptionState.DISABLED,
    generateBuilderConsumer = OptionState.DISABLED,
    generateConditionalHelper = OptionState.DISABLED,
    generateVarArgsHelpers = OptionState.DISABLED,
    generateStringFormatHelpers = OptionState.DISABLED,
    generateAddToCollectionHelpers = OptionState.DISABLED,
    generateUnboxedOptional = OptionState.DISABLED,
    generateWithInterface = OptionState.DISABLED,
    usingArrayListBuilder = OptionState.DISABLED,
    usingArrayListBuilderWithElementBuilders = OptionState.DISABLED,
    usingHashSetBuilder = OptionState.DISABLED,
    usingHashSetBuilderWithElementBuilders = OptionState.DISABLED,
    usingHashMapBuilder = OptionState.DISABLED,
    usingGeneratedAnnotation = OptionState.DISABLED,
    usingBuilderImplementationAnnotation = OptionState.DISABLED,
    usingJacksonDeserializerAnnotation = OptionState.DISABLED,
    generateJacksonModule = OptionState.DISABLED,
    builderSuffix = "MinimalBuilder",
    setterSuffix = ""
))
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
@Inherited
public @interface SimpleMinimalBuilder {}

The exact name can be discussed (SimpleMinimalBuilder, MinimalBuilder, @SimpleBuilder.Minimal, etc.).

Requirements

  1. Annotation definition (core/src/main/java/.../SimpleMinimalBuilder.java)

    • Must be implemented purely as a @SimpleBuilder.Template with all optional features disabled.
    • Must be @Inherited so subclasses get a builder too.
  2. Dedicated test class (processor/src/test/java/.../SimpleMinimalBuilderTest.java)

    • Follow the pattern of BuilderConfigurationReaderTest.resolveConfiguration_AllLayersTogether_CompleteChain and assert the full generated source for a minimal builder.
    • Cover standalone usage and inheritance from a parent annotated with @SimpleMinimalBuilder.
    • Existing tests that today create ad-hoc "minimal" templates should be migrated to use @SimpleMinimalBuilder where appropriate.
  3. Documentation (docs/CONFIGURATION.md)

    • Add a section describing @SimpleMinimalBuilder under ## Template Annotations or a new sub-section.
    • List exactly which features are disabled and why.
  4. Example usage (example/src/main/java/...)

    • Add a small DTO annotated with @SimpleMinimalBuilder to demonstrate usage.
    • Ensure the example module builds and its generated output is as expected.

Acceptance Criteria

  • @SimpleMinimalBuilder (or chosen name) is available in core.
  • It generates only build(), create(), and the field setters — no suppliers, consumers, varargs, collection helpers, with interface, Jackson, or generated annotations.
  • New test class validates full generated source for minimal builders.
  • Existing minimal-related tests prefer the new annotation.
  • Example DTO in example module.
  • Documentation updated in docs/CONFIGURATION.md, including link to example builder of example module
  • mvn test passes end-to-end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions