apple/pkl · error · JavaCodeGeneratorException
Cannot generate Java code for a Pkl standard library module
Error message
Cannot generate Java code for a Pkl standard library module (`${schema.moduleUri}`). What it means
The javaFile getter refuses to generate Java code when the schema's module URI uses the `pkl:` scheme, i.e. the module is part of the Pkl standard library. Stdlib modules are provided by Pkl itself; generating bindings for them is not meaningful or supported.
Solutions
- Target your own module file/URI (e.g. my/module.pkl) instead of a `pkl:` stdlib URI.
- If you need stdlib types, depend on the library's pre-built mappings (pkl-config-java) rather than generating them.
- Check your PklProject dependencies so imports resolve to your modules, not stdlib.
- If you genuinely need stdlib bindings, file an issue upstream.
Example fix
// before pkl gen java pkl:base // after pkl gen java com/example/config/AppConfig.pkl
Defensive patterns
Strategy: validation
Validate before calling
require(!moduleUri.toString().startsWith("pkl:")) { "cannot generate bindings for stdlib module" } Type guard
fun isStdlibModule(uri: URI) = uri.scheme == "pkl"
Try / catch
try { gen.javaFile } catch (e: JavaCodeGeneratorException) { if ("standard library module" in e.message!!) skipModule() else throw e } Prevention
- Point codegen at your own project modules only
- Check PklProject dependency resolution for accidental stdlib targets
- Filter task inputs to exclude pkl: URIs
When it happens
Trigger: Passing a module URI such as pkl:base or pkl:format directly to the Java code generator, or a project dependency resolving to a stdlib module instead of a user module.
Common situations: Mistyping the target module in the CLI invocation, intending to extend stdlib types, or wiring the codegen to analyze pkl.base rather than your own amir/pkl module.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Pkl function types are not supported by the Java code…
- Pkl ` ` types are not supported by the Java code generator.
- Annotation `$fqn` is not a valid Java class. The name of…
- Cannot generate Java enum class for Pkl type alias
- Cannot generate Java enum class for Pkl type alias
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/094937aa4e0e3894.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt:196
}
return AnnotationSpec.builder(className).build()
}
private val javaFileName: String
get() {
val (packageName, className) = nameMapper.map(schema.moduleName)
val dirPath = packageName.replace('.', '/')
return if (dirPath.isEmpty()) {
"java/$className.java"
} else {
"java/$dirPath/$className.java"
}
}
val javaFile: String
get() {
if (schema.moduleUri.scheme == "pkl") {
throw JavaCodeGeneratorException(
"Cannot generate Java code for a Pkl standard library module (`${schema.moduleUri}`)."
)
}
val pModuleClass = schema.moduleClass
val moduleClass = generateTypeSpec(pModuleClass, schema)
for (pClass in schema.classes.values) {
moduleClass.addType(generateTypeSpec(pClass, schema).build())
}
for (typeAlias in schema.typeAliases.values) {
val stringLiterals = mutableSetOf<String>()
if (CodeGeneratorUtils.isRepresentableAsEnum(typeAlias.aliasedType, stringLiterals)) {
moduleClass.addType(generateEnumTypeSpec(typeAlias, stringLiterals).build())
}
}
// generate static append method for module classes w/o parent class; reuse in subclasses andView on GitHub (pinned to f3efcbfc9b)