Compatibility issue with Kotlin stdlib when generating code manually from CLI #70

Closed
opened 2025-12-30 01:20:22 +01:00 by adam · 4 comments
Owner

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-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.

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-java` README: ```bash 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.
adam closed this issue 2025-12-30 01:20:23 +01:00
Author
Owner

@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.

@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`.
Author
Owner

@theKnightsOfRohan 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.

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:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/pkl/codegen/java/Main has been compiled by a more recent ver
sion of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)

The specific java 8 version is 1.8.0_341.

@theKnightsOfRohan 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`. 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](https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.7.10), and [maven central](https://central.sonatype.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.7.10/versions) 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: ``` Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: org/pkl/codegen/java/Main has been compiled by a more recent ver sion of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:756) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:473) at java.net.URLClassLoader.access$100(URLClassLoader.java:74) at java.net.URLClassLoader$1.run(URLClassLoader.java:369) at java.net.URLClassLoader$1.run(URLClassLoader.java:363) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:362) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601) ``` The specific java 8 version is 1.8.0_341.
Author
Owner

@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.

@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.
Author
Owner

@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!

@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!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#70