{"record":{"id":"094937aa4e0e3894","repo":"apple/pkl","slug":"cannot-generate-java-code-for-a-pkl-standard-libra","errorCode":null,"errorMessage":"Cannot generate Java code for a Pkl standard library module (`${schema.moduleUri}`).","messagePattern":"Cannot generate Java code for a Pkl standard library module \\(`(.+?)`\\)\\.","errorType":"exception","errorClass":"JavaCodeGeneratorException","httpStatus":null,"severity":"error","filePath":"pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt","lineNumber":196,"sourceCode":"        }\n      return AnnotationSpec.builder(className).build()\n    }\n\n  private val javaFileName: String\n    get() {\n      val (packageName, className) = nameMapper.map(schema.moduleName)\n      val dirPath = packageName.replace('.', '/')\n      return if (dirPath.isEmpty()) {\n        \"java/$className.java\"\n      } else {\n        \"java/$dirPath/$className.java\"\n      }\n    }\n\n  val javaFile: String\n    get() {\n      if (schema.moduleUri.scheme == \"pkl\") {\n        throw JavaCodeGeneratorException(\n          \"Cannot generate Java code for a Pkl standard library module (`${schema.moduleUri}`).\"\n        )\n      }\n\n      val pModuleClass = schema.moduleClass\n      val moduleClass = generateTypeSpec(pModuleClass, schema)\n\n      for (pClass in schema.classes.values) {\n        moduleClass.addType(generateTypeSpec(pClass, schema).build())\n      }\n\n      for (typeAlias in schema.typeAliases.values) {\n        val stringLiterals = mutableSetOf<String>()\n        if (CodeGeneratorUtils.isRepresentableAsEnum(typeAlias.aliasedType, stringLiterals)) {\n          moduleClass.addType(generateEnumTypeSpec(typeAlias, stringLiterals).build())\n        }\n      }\n      // generate static append method for module classes w/o parent class; reuse in subclasses and","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt#L178-L214","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npkl gen java pkl:base\n// after\npkl gen java com/example/config/AppConfig.pkl","handlingStrategy":"validation","validationCode":"require(!moduleUri.toString().startsWith(\"pkl:\")) { \"cannot generate bindings for stdlib module\" }","typeGuard":"fun isStdlibModule(uri: URI) = uri.scheme == \"pkl\"","tryCatchPattern":"try { gen.javaFile } catch (e: JavaCodeGeneratorException) { if (\"standard library module\" in e.message!!) skipModule() else throw e }","preventionTips":["Point codegen at your own project modules only","Check PklProject dependency resolution for accidental stdlib targets","Filter task inputs to exclude pkl: URIs"],"tags":["codegen","pkl-stdlib","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}