tools-build

Mark Wardle 2024-11-14T12:03:19.056119Z

I am hitting the issue in which if I compile a uberjar for release with JDK21 or above, running the uberjar on JDK11 complains about a missing class java.lang.NoClassDefFoundError: java/util/SequencedCollection This means that I must remember to switch to JDK11 to create the uberjar. I am about to simply print a warning in my tools.build build file when I have the wrong Java version but this isn't an ideal solution. Is there any way of specifying the Java version to be used? :java-opts and -target won't work I think because of subprocesses. I could do something with tools build api and 'process` to use java_home to get the right binary for a specific JDK version and then specify that using :java-cmd. The better way would be to be able to use whatever modern JDK we have on the system but the target parameter is passed through to any subprocesses. Any other ideas or examples of any of the options?

2024-11-14T12:13:43.850189Z

I have this on my build file, kind of the same you are proposing there :

(defn- check-jvm []
  (let [jvm-version (-> (System/getProperty "java.specification.version")
                        Integer/parseInt)]
    (when (>= jvm-version 21)
      (throw (ex-info "Not building with JVM >= 21 because of the SequencedCollection issue." {})))
    (println "Building with JVM " jvm-version)))

👍 1
Mark Wardle 2024-11-14T14:52:39.057629Z

Thanks. I will copy your approach for now.