pkl icon indicating copy to clipboard operation
pkl copied to clipboard

Compatibility issue with Kotlin stdlib when generating code manually from CLI

Open theKnightsOfRohan opened this issue 4 months ago • 0 comments

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-java README:

java -cp "${PWD}/bin:${PWD}/lib/*:" -jar lib/pkl-codegen-java-0.25.2.jar -o generated $(PWD)/src/BubbleData.pkl

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, and pkl-core-0.25.2.jar in my lib folder as per the dependencies listed on maven central, where I downloaded the generator library from, I get the below error:

Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
        at org.pkl.codegen.java.Main.main(Main.kt)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
        ... 1 more

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.

theKnightsOfRohan avatar Feb 15 '24 00:02 theKnightsOfRohan