reflective-fluent-builders:generate-builders

Full name:

io.github.tobi-laa:reflective-fluent-builders-maven-plugin:2.1.1:generate-builders

Description:

A maven plugin for generating fluent builders for existing classes with the help of reflection. This can be useful in cases where it is not possible (or very hard) to change the sources of said classes to generate builders directly.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: test.
  • The goal is not marked as thread-safe and thus does not support parallel builds.
  • Binds by default to the lifecycle phase: generate-test-sources.

Required Parameters

Name Type Since Description
<includes> Set<Include> 1.0.0

Specifies the classes for which to generate builders.

A single <include>..</include> can be specified in the following ways:

  • <include>
        <className>fully.qualified.ClassName</className>
    </include>
  • <include>
        <packageName>fully.qualified.package.name</packageName>
    </include>

Optional Parameters

Name Type Since Description
<addCompileSourceRoot> boolean 1.0.0

Specifies whether to add target as a source folder to this project. As this is the behaviour that most projects will want, the default is true.


Default: true
<adderPattern> String 2.0.0

The pattern used for identifying adder methods via reflection when analyzing classes. This needs to be a valid regular expression with the first group being the name of the property. The default value is:

add(.+)


Default: add(.+)
<addersEnabled> boolean 2.0.0

If this is set to true, the generated builders will use adder methods. Adder methods will take precedence over setters if both are available.


Default: true
<builderPackage> String 1.0.0

The package in which to place the generated builders.

Relative paths can be specified with the help of <PACKAGE_NAME>. As <PACKAGE_NAME> is also the default value, builders will be placed within the same package as the classes built by them if nothing else is specified.


Default: <PACKAGE_NAME>
<builderSuffix> String 1.0.0

The suffix to append to builder classes. The default value is Builder, meaning a builder for a class named Person would be named PersonBuilder.


Default: Builder
<deleteOrphanedBuilders> boolean 1.7.0

Specifies whether to delete orphaned builders from the directory.

A builder is considered orphaned if it would no longer be generated during a clean build, be it due to a class having been deleted or renamed or due to the configuration having been changed.

As this is the behaviour that most projects will want, the default is true.


Default: true
<directFieldAccessEnabled> boolean 2.0.0

If this is set to true, the generated builders will use direct field access if possible and if no setter is available.


Default: true
<excludes> Set<Exclude> 1.0.0

Specifies classes to be excluded when generating builders.

A single <exclude>..</exclude> can be specified in the following ways:

  • <exclude>
        <className>fully.qualified.ClassName</className>
    </exclude>
  • <exclude>
        <classRegex>regex.for.Class[A-Z]+</className>
    </exclude>
  • <exclude>
        <packageName>fully.qualified.package.name</packageName>
    </exclude>
  • <exclude>
        <packageRegex>regex.for.packages.[a-z]+</packageRegex>
    </exclude>

If not specified, the default value is set to exclude classes ending with Builder or BuilderImpl.

<getAndAddEnabled> boolean 1.0.0

If this is set to true, it is assumed that getters of collections without a corresponding setter will lazily initialize the underlying collection. The generated builders will use a get-and-add paradigm where necessary to construct a collection.


Default: true
<getterPrefix> String 1.0.0

The prefix used for identifying getter methods via reflection when analyzing classes. The default value is get.


Default: get
<hierarchyCollection> MojoParams$HierarchyCollection 1.0.0

Properties relating to hierarchy collection of classes.

  • hierarchyCollection.excludes

    Specifies classes to be excluded from the hierarchy collection. They will not be added to the result. Furthermore, if a class from excludes is encountered during ancestor traversal of the starting class it is immediately stopped.

    A single <exclude>..</exclude> can be specified in the following ways:

    • <exclude>
          <className>fully.qualified.ClassName</className>
      </exclude>
    • <exclude>
          <classRegex>regex.for.Class[A-Z]+</className>
      </exclude>
    • <exclude>
          <packageName>fully.qualified.package.name</packageName>
      </exclude>
    • <exclude>
          <packageRegex>regex.for.packages.[a-z]+</packageRegex>
      </exclude>

<setterPrefix> String 1.0.0

The prefix used for identifying setter methods via reflection when analyzing classes. The default value is set.


Default: set
<target> File 1.0.0

The target directory in which to place the generated builders.

If not specified, the default value is dependent on the org.apache.maven.plugins.annotations.LifecyclePhase.

For any test-related phase, the default target directory will be the following:
${project.build.directory}/generated-test-sources/builders
For any other phase, the default target directory will be:
${project.build.directory}/generated-sources/builders

Parameter Details

<addCompileSourceRoot>

Specifies whether to add target as a source folder to this project. As this is the behaviour that most projects will want, the default is true.

  • Type: boolean
  • Since: 1.0.0
  • Required: No
  • Default: true

<adderPattern>

The pattern used for identifying adder methods via reflection when analyzing classes. This needs to be a valid regular expression with the first group being the name of the property. The default value is:

add(.+)

  • Type: java.lang.String
  • Since: 2.0.0
  • Required: No
  • Default: add(.+)

<addersEnabled>

If this is set to true, the generated builders will use adder methods. Adder methods will take precedence over setters if both are available.

  • Type: boolean
  • Since: 2.0.0
  • Required: No
  • Default: true

<builderPackage>

The package in which to place the generated builders.

Relative paths can be specified with the help of <PACKAGE_NAME>. As <PACKAGE_NAME> is also the default value, builders will be placed within the same package as the classes built by them if nothing else is specified.

  • Type: java.lang.String
  • Since: 1.0.0
  • Required: No
  • Default: <PACKAGE_NAME>

<builderSuffix>

The suffix to append to builder classes. The default value is Builder, meaning a builder for a class named Person would be named PersonBuilder.

  • Type: java.lang.String
  • Since: 1.0.0
  • Required: No
  • Default: Builder

<deleteOrphanedBuilders>

Specifies whether to delete orphaned builders from the directory.

A builder is considered orphaned if it would no longer be generated during a clean build, be it due to a class having been deleted or renamed or due to the configuration having been changed.

As this is the behaviour that most projects will want, the default is true.

  • Type: boolean
  • Since: 1.7.0
  • Required: No
  • Default: true

<directFieldAccessEnabled>

If this is set to true, the generated builders will use direct field access if possible and if no setter is available.

  • Type: boolean
  • Since: 2.0.0
  • Required: No
  • Default: true

<excludes>

Specifies classes to be excluded when generating builders.

A single <exclude>..</exclude> can be specified in the following ways:

  • <exclude>
        <className>fully.qualified.ClassName</className>
    </exclude>
  • <exclude>
        <classRegex>regex.for.Class[A-Z]+</className>
    </exclude>
  • <exclude>
        <packageName>fully.qualified.package.name</packageName>
    </exclude>
  • <exclude>
        <packageRegex>regex.for.packages.[a-z]+</packageRegex>
    </exclude>

If not specified, the default value is set to exclude classes ending with Builder or BuilderImpl.

  • Type: java.util.Set<io.github.tobi.laa.reflective.fluent.builders.mojo.Exclude>
  • Since: 1.0.0
  • Required: No

<getAndAddEnabled>

If this is set to true, it is assumed that getters of collections without a corresponding setter will lazily initialize the underlying collection. The generated builders will use a get-and-add paradigm where necessary to construct a collection.

  • Type: boolean
  • Since: 1.0.0
  • Required: No
  • Default: true

<getterPrefix>

The prefix used for identifying getter methods via reflection when analyzing classes. The default value is get.

  • Type: java.lang.String
  • Since: 1.0.0
  • Required: No
  • Default: get

<hierarchyCollection>

Properties relating to hierarchy collection of classes.

  • hierarchyCollection.excludes

    Specifies classes to be excluded from the hierarchy collection. They will not be added to the result. Furthermore, if a class from excludes is encountered during ancestor traversal of the starting class it is immediately stopped.

    A single <exclude>..</exclude> can be specified in the following ways:

    • <exclude>
          <className>fully.qualified.ClassName</className>
      </exclude>
    • <exclude>
          <classRegex>regex.for.Class[A-Z]+</className>
      </exclude>
    • <exclude>
          <packageName>fully.qualified.package.name</packageName>
      </exclude>
    • <exclude>
          <packageRegex>regex.for.packages.[a-z]+</packageRegex>
      </exclude>

  • Type: io.github.tobi.laa.reflective.fluent.builders.mojo.MojoParams$HierarchyCollection
  • Since: 1.0.0
  • Required: No

<includes>

Specifies the classes for which to generate builders.

A single <include>..</include> can be specified in the following ways:

  • <include>
        <className>fully.qualified.ClassName</className>
    </include>
  • <include>
        <packageName>fully.qualified.package.name</packageName>
    </include>

  • Type: java.util.Set<io.github.tobi.laa.reflective.fluent.builders.mojo.Include>
  • Since: 1.0.0
  • Required: Yes

<setterPrefix>

The prefix used for identifying setter methods via reflection when analyzing classes. The default value is set.

  • Type: java.lang.String
  • Since: 1.0.0
  • Required: No
  • Default: set

<target>

The target directory in which to place the generated builders.

If not specified, the default value is dependent on the org.apache.maven.plugins.annotations.LifecyclePhase.

For any test-related phase, the default target directory will be the following:
${project.build.directory}/generated-test-sources/builders
For any other phase, the default target directory will be:
${project.build.directory}/generated-sources/builders

  • Type: java.io.File
  • Since: 1.0.0
  • Required: No