Allow overriding Java/Kotlin package name in codegen #152

Closed
opened 2025-12-30 01:21:35 +01:00 by adam · 0 comments
Owner

Originally created by @netvl on GitHub (Apr 26, 2024).

Currently the package name for the classes generated from Pkl modules (when using the Gradle plugin or the CLI) is always derived from the module name defined within the Pkl module file:

open module org.example.Whatever

This is, however, not very flexible, because there are use cases when the module name's prefix and the desired Java/Kotlin package name may differ. For example, when publishing Pkl packages (with PklProject) it is expected that the module name prefix matches the Pkl package name:

// Within package://some-repo.com/some-org/some_package@1.0.0#/SomeModule.pkl:

open module some_package.SomeModule

...

However, if a project already uses some particular JVM package name, it would be necessary either to change the Pkl package name:

package://some-repo.com/some-org/com.some.org.some_package@1.0.0#/SomeModule.pkl

which is often inconvenient, or to live with the fact that Java classes will have different package names.

It would be nice if there was an option to override the generated classes' package name via a CLI argument or via a Gradle configuration option:

pkl.javaCodeGenerators.create("someClasses") {
    packageMappings.put("some_package", "com.some.org.config")
}
Originally created by @netvl on GitHub (Apr 26, 2024). Currently the package name for the classes generated from Pkl modules (when using the Gradle plugin or the CLI) is always derived from the module name defined within the Pkl module file: ``` open module org.example.Whatever ``` This is, however, not very flexible, because there are use cases when the module name's prefix and the desired Java/Kotlin package name may differ. For example, when publishing Pkl packages (with `PklProject`) it is expected that the module name prefix matches the Pkl package name: ``` // Within package://some-repo.com/some-org/some_package@1.0.0#/SomeModule.pkl: open module some_package.SomeModule ... ``` However, if a project already uses some particular JVM package name, it would be necessary either to change the Pkl package name: ``` package://some-repo.com/some-org/com.some.org.some_package@1.0.0#/SomeModule.pkl ``` which is often inconvenient, or to live with the fact that Java classes will have different package names. It would be nice if there was an option to override the generated classes' package name via a CLI argument or via a Gradle configuration option: ``` pkl.javaCodeGenerators.create("someClasses") { packageMappings.put("some_package", "com.some.org.config") } ```
adam closed this issue 2025-12-30 01:21:35 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#152