Closed maciejwalkowiak closed 10 months ago
For that the minimum Java version would have to be bumped to 16+ (likely 17 makes more sense) which means quite a bit of updates to Gradle files.
Hi @maciejwalkowiak, thanks a lot for opening the issue!
To clarify: does the workaround you posted (placing @Builder
on the constructor of the record
) work - as in, does Jilt generate a Builder that can be used to create a valid instance of the record
?
Thanks, Adam
Yes it does, the workaround works!
Adding support for records without the workaround is trivial (it's a one liner). Upgrading Gradle config to make it work with Java 17 is more work.
Is the problem in this line?
Because there is a new ElementType
enum value for record
s in Java 16+?
(Sorry, I didn’t have time to look into this on a laptop yet 😛)
OK, I've finally had some time to dig into this issue 🙂.
As it turns out, the declaration of the @Builder
annotation, and its usage of ElementType
is not the problem, since TYPE
still works for records - the JavaDocs of ElementType
say:
public enum ElementType {
/** Class, interface (including annotation interface), enum, or record
* declaration */
TYPE,
// ...
But, the problem is in this code: https://github.com/skinny85/jilt/blob/5646306d00095552d39b323698bf644acfa8c565/src/main/java/org/jilt/internal/BuilderGeneratorFactory.java#L35-L35
Since the ElementKind
enum does have a new value for records, ElementKind.RECORD
.
But that's great news - it means there's a chance it's possible to add record
support without making the library require Java 16+, which I'd like to avoid if possible (the problem is not the Gradle configuration - I've already migrated it to 8.5 on the develop
branch. I just want the library to be as widely usable for folks as possible).
I'll update the issue once I know more.
OK, I managed to figure it out. I'll do a 1.3
release fixing this issue sometime this week.
This has been fixed in the latest release, cc.jilt:jilt:1.3
.
I'm resolving this one, please comment if you encounter any problems related to this, and I'll reopen the issue.
Fantastic, thanks @skinny85!
Putting
@Builder
on the Java record like:results in:
The workaround is to create compact constructor:
Ideally, this would not be needed and it would be enough to put
@Builder
on the record declaration.