Skip to content

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

protobufel2
Copy link

  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
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
Copy link
Member

@bioball bioball left a 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,
Copy link
Member

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.

Copy link
Author

@protobufel2 protobufel2 Feb 28, 2025

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

Copy link
Member

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.

Copy link
Author

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?

Copy link
Member

@bioball bioball Mar 1, 2025

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.

Copy link
Contributor

@stackoverflow stackoverflow left a 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:*'
@protobufel2
Copy link
Author

@bioball, @stackoverflow, @arouel please review and approve this hopefully final update to the PR, including:

  1. introduced 2 new optional features, useWithers and useLombokBuilders, to the plain Java records generation - as per your request
  2. refactored JavaRecordCodeGeneratorTest with JUnit 5 ParameterizedClass and tested all 3 cases: plain record generation, with Withers, and with Lombok Builders
  3. Submitted the Java Records Code Generation SPICE SPICE-0017: Java Records Code Generation pkl-evolution#19 for your review and approval.

# 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
@protobufel2
Copy link
Author

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
@protobufel2
Copy link
Author

Reconciled with the unrelated 'generatedAnnotation' changing to addGeneratedAnnotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants