-
Notifications
You must be signed in to change notification settings - Fork 321
Java class and record generators and friends side-by-side #970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
1. Java code generation via Java Records and 2. Wither implementation close to JEP 468 3. extra "generateRecords" option in Gradle JavaCodeGenTask 4. extra "--generate-records" option in pkl-codegen-java CLI 5. updated docs see pkl-codegen-java/README.md
1. Java code generation via Java Records and 2. Wither implementation close to JEP 468 3. extra "generateRecords" option in Gradle JavaCodeGenTask 4. extra "--generate-records" option in pkl-codegen-java CLI 5. updated docs see pkl-codegen-java/README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR! This is a much needed feature.
I haven't looked at this in detail yet; worth discussing the implementation first.
Also, it's a little hard to review this because of the duplicated JavaRecordCodeGenerator
class. Can we consolidate this?
* | ||
* This overrides any Java class generation related options! | ||
*/ | ||
val generateRecords: Boolean = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just flip this around and have a flag called generatePojos
which defaults to false.
By default, the code generator should be generating records whenever it can (all Pkl users are on Java 17).
This flag would just be for folks that are migrating and don't want to suffer a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding flipping generateRecords
to the default true
, it'd be very distractive, incompatible change by breaking all regenerated Java object models' usage, necessitating the corresponding boolean flip in Gradle extension and any such Java generation via using pkl-core
or pkl-config-java
by the affected users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's okay; for users that want minimal breakage, they can add generatePojos = true
to retain the current code generator output. For most users, this should be a matter of adding a line to their build.gradle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we follow the industry practice of deprecation, keep things as compatible as possible for one, two releases before make it the breaking change? I guess, until Pkl goes 1.0.0 we could've followed Kotlin's model of making such breaking changes after a couple of minor releases, especially when it doesn't change the Pkl itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downside of that is: it is harder for new users that are adopting Pkl (the code generator has less sensible defaults).
We usually try to minimize breaking changes, but this one feels quite tolerable to me. I'm also okay with already making the generatePojos
option already deprecated, and eventually removed. Once we ship 1.x, we will be stricter about breaking changes.
pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaRecordCodeGenerator.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Generating records is something we were already discussing since we switched to Java 17.
Just left some comments for the high level archtecture.
1. Java code generation via Java Records and 2. Wither implementation close to JEP 468 (optional) 3. extra "generateRecords" option in Gradle JavaCodeGenTask 4. extra "--generate-records" option in pkl-codegen-java CLI 5. extra "--use-withers" and "--use-lombok-builders" options in Gradle, CLI 5. updated docs see pkl-codegen-java/README.md - to be moved to SPICE
command: gw updateDependencyLocks dependencies \ --update-locks 'org.junit:*,org.junit.jupiter:*,org.junit.platform:*'
@bioball, @stackoverflow, @arouel please review and approve this hopefully final update to the PR, including:
|
# Conflicts: # pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/CliJavaCodeGeneratorOptions.kt # pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt
Also merged and reconciled with the unrelated 'generatedAnnotation' PR by @arouel released today into main, enabling it in both Java CodeGenerator and JavaRecordCodeGenerator for parity. |
# Conflicts: # pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/CliJavaCodeGeneratorOptions.kt # pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt
Reconciled with the unrelated 'generatedAnnotation' changing to |
see pkl-codegen-java/README.md