Skip to content

Include resource files in pkl_java_library output#110

Merged
KushalP merged 5 commits intoapple:mainfrom
ByteSmithAI:fix_pkl_java_library2
Oct 24, 2025
Merged

Include resource files in pkl_java_library output#110
KushalP merged 5 commits intoapple:mainfrom
ByteSmithAI:fix_pkl_java_library2

Conversation

@ByteSmithAI
Copy link
Copy Markdown
Contributor

Fix pkl_java_library to include .properties files generated by pkl codegen in the final JAR. Previously, these mapper metadata files were only present in the intermediate srcjar but not in the compiled output JAR.

This change:

  • Adds _pkl_java_resource_jar rule to extract resources from srcjar
  • Uses java_single_jar to merge compiled classes and resources
  • Wraps result with java_import to provide JavaInfo for deps
  • Maintains backward compatibility with module_path feature

See issue: #109

bruno4apple and others added 2 commits October 19, 2025 18:33
Fix pkl_java_library to include .properties files generated by
pkl codegen in the final JAR. Previously, these mapper metadata
files were only present in the intermediate srcjar but not in the
compiled output JAR.

This change:
- Adds _pkl_java_resource_jar rule to extract resources from srcjar
- Uses java_single_jar to merge compiled classes and resources
- Wraps result with java_import to provide JavaInfo for deps
- Maintains backward compatibility with module_path feature

Addresses issue raised in bazelbuild/rules_java#275 by using the
recommended java_single_jar approach for including generated
resources.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add test demonstrating that mapper .properties files are required
for polymorphic type resolution. The test creates a Shelter with
mixed Dog and Cat instances (both extending abstract Animal class)
and verifies each deserializes to the correct concrete type.

This validates that the .properties files generated by pkl codegen
are correctly included in the JAR and used by ClassRegistry for
runtime type mapping.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
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.

LGTM from the Pkl side of things. Would like a thumbs from @sitaktif, @KushalP or someone else that can review the Bazel side of this!

Comment thread tests/pkl_codegen_java/PolymorphismTest.java Outdated
Comment thread tests/pkl_codegen_java/PolymorphismTest.java Outdated
Comment thread tests/pkl_codegen_java/PolymorphismTest.java Outdated
@ByteSmithAI ByteSmithAI marked this pull request as draft October 21, 2025 23:18
Move inline Pkl configuration to external shelter.pkl file following
the pattern established in TestPklCodegen. This improves test
maintainability and uses try-with-resources for proper resource
management.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ByteSmithAI ByteSmithAI marked this pull request as ready for review October 21, 2025 23:35
Comment thread pkl/private/pkl_codegen_java.bzl Outdated
Comment thread pkl/private/pkl_codegen_java.bzl
Remove the `|| true` from the zip command that creates the resource JAR,
allowing real errors (e.g., disk full, permissions) to properly fail the
build. Add explicit check for empty resources directory to handle this
case gracefully by creating an empty JAR, rather than silently ignoring
zip command failures.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@sitaktif sitaktif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

Comment thread MODULE.bazel
@KushalP KushalP merged commit dc4ad67 into apple:main Oct 24, 2025
3 checks passed
@ByteSmithAI ByteSmithAI deleted the fix_pkl_java_library2 branch October 24, 2025 15:39
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.

5 participants