mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Compatibility issue with Kotlin stdlib when generating code manually from CLI #70
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @theKnightsOfRohan on GitHub (Feb 15, 2024).
I am trying to use pkl to generate a java class which holds config and constants used throughout my project. My project does not have a build system like gradle or maven, and instead I am compiling and running everything manually through the CLI. The command I am using to generate the class is as follows, taken and adapted directly from the
pkl-jvm-examples/codegen-javaREADME:When using the above command, with
pkl-codegen-java-0.25.2.jar,javapoet-1.13.0.jar,pkl-commons-0.25.2.jar,kotlin-stdlib-jdk8-1.7.10.jar, andpkl-core-0.25.2.jarin my lib folder as per the dependencies listed on maven central, where I downloaded the generator library from, I get the below error:This exception occurs when the Kotlin standard library is not found in the classpath.This error occurred both without and with the kotlin stdlib jar in my lib folder. I tried manually specifying it as a third part of the classpath, but the same error occurred.
The next thing I thought of was that the jar I downloaded was somehow corrupted or unusable, or didn't contain the necessary class. This bore fruit, in that the Kotlin stdlib version 1.7.10 did not contain the kotlin/jvm/internal/Intrinsics class, as determined by jar tf. So, I tried switching to the current JDK version of the Kotlin standard library, as I know that the codegen jar is supposed to be run with JDK 11 or above. Using the command
jar tf ./lib/kotlin-stdlib-1.9.21.jar | grep kotlin.jvm.internal.Intrinsics, I did find that the class exists, but the error still persisted when I tried to generate the class again.The last thing I did was to see if there was some sort of versioning issue, so I tried both the 1.9.20 and 1.9.22 versions of the Kotlin stdlib from maven, but neither of those worked either.
Given all of this context, would it be possible for you to list the exact versions of java, the kotlin standard library, and any dependencies used by the java code generator? In addition, is there some sort of error I am making when attempting this utility? For additional information, I'm using JDK 21.0.1, and I am still able to use the core library to read the data from the .pkl file normally.
@odenix commented on GitHub (Feb 15, 2024):
You're missing most of the Kotlin stdlib, i.e., the dependencies of
stdlib-jdk8-1.7.10.jar.@theKnightsOfRohan commented on GitHub (Feb 15, 2024):
You see, that's what I thought, and I tried it one more time just to make sure I hadn't accidentally overlooked something. I downloaded the exact jar you said from the maven repository, and maven central but the compilation error still persists. I also tried compiling with java 8, but that doesn't work for an entirely different reason, in that java 8 is too old to read the .class file, as stated by the below exception:
The specific java 8 version is 1.8.0_341.
@odenix commented on GitHub (Feb 15, 2024):
What I'm trying to say is that you're missing the dependencies of
kotlin-stdlib-jdk8(see Dependencies tab on Maven Central). I strongly recommend to save yourself the hassle and use a build tool.@theKnightsOfRohan commented on GitHub (Feb 15, 2024):
Oh, I see what you mean. Yeah, I guess a build system would make it a lot easier. I'll work with this more on my own. Thanks for the help!