Motivation
Allow users to explicitly control the package in which generated builder classes are created.
This is particularly useful for @SimpleBuilderFor, where the target type may belong to a third-party package and the generated builder should live in the application’s own package. Or for usecases where developers want to collect builders in one central package.
Proposed API
Add a package configuration option to the existing @SimpleBuilder.Options:
@SimpleBuilderFor(
value = ExternalUser.class,
options = @SimpleBuilder.Options(
packageName = "com.example.generated"
)
)
class ExternalBuilders {
}
The option should use the existing @SimpleBuilder.Options mechanism rather than adding a separate parameter to @SimpleBuilderFor. This option should always default to the package of the class for which it is generated. In case of SimpleBuilderFor it is the class where the annotation is positioned.
Example
Given:
package com.vendor.api;
public class ExternalUser {
// ...
}
the generated builder could be placed in:
com.example.generated.ExternalUserBuilder
instead of deriving its package solely from the target type.
Requirements
- Add packageName to the existing @SimpleBuilder.Options.
- Preserve the current default behavior when packageName is not specified.
- Apply the option consistently to all relevant builder-generation mechanisms.
- Ensure generated imports and references remain valid.
- Validate invalid package names at compile time.
- Ensure that the constructors or setters are reachable. For example package-private (and protected) constructors, setters or getters should be handled as if they are not there because the builder would afterwards be placed in a totally different package
Relationship to @SimpleBuilderFor
In #293 we implement a feature for generation without adding annotation directly on this class. This feature here should be implemented as an independent, reusable configuration feature.
@SimpleBuilderFor can then use it without introducing external-type-specific package configuration.
Goal
Provide explicit control over the package of generated builders while keeping package configuration part of the existing Simple Builders options model.
Motivation
Allow users to explicitly control the package in which generated builder classes are created.
This is particularly useful for @SimpleBuilderFor, where the target type may belong to a third-party package and the generated builder should live in the application’s own package. Or for usecases where developers want to collect builders in one central package.
Proposed API
Add a package configuration option to the existing @SimpleBuilder.Options:
The option should use the existing @SimpleBuilder.Options mechanism rather than adding a separate parameter to @SimpleBuilderFor. This option should always default to the package of the class for which it is generated. In case of SimpleBuilderFor it is the class where the annotation is positioned.
Example
Given:
the generated builder could be placed in:
instead of deriving its package solely from the target type.
Requirements
Relationship to @SimpleBuilderFor
In #293 we implement a feature for generation without adding annotation directly on this class. This feature here should be implemented as an independent, reusable configuration feature.
@SimpleBuilderFor can then use it without introducing external-type-specific package configuration.
Goal
Provide explicit control over the package of generated builders while keeping package configuration part of the existing Simple Builders options model.