Fork me on GitHub
#tools-build
<
2024-01-27
>
jussi21:01:43

Hi, run into weird issue when trying to build a mixed clojure/java project into an uberjar. I've been looking at this for some time now and it is very possible that https://en.wikipedia.org/wiki/User_error#PEBKAC/PEBCAK/PICNIC.

$ java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment (Red_Hat-17.0.9.0.9-3) (build 17.0.9+9)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.9.0.9-3) (build 17.0.9+9, mixed mode, sharing)
$ clj --version
Clojure CLI version 1.11.1.1113
$ clj -T:build uber
Execution error (IllegalArgumentException) at com.sun.tools.javac.main.Arguments/reportDiag (Arguments.java:889).
error: release version 17 not supported

Full report at:
/tmp/clojure-6391560421448438714.edn
My deps.edn contains
:build
  {:deps {io.github.clojure/tools.build {:git/tag "v0.9.6" :git/sha "8e78bcc"}}
   :ns-default build}
My build.clj file looks like this
(ns build
  (:require
   [clojure.tools.build.api :as b]))

(def class-dir "target/classes")
(def jar-file "api.jar")

;; delay to defer side effects (artifact downloads)
(def basis (delay (b/create-basis {:project "deps.edn"})))

(defn clean [_]
  (b/delete {:path "target"}))

(defn compile-java [_]
  (b/javac {:src-dirs ["java"]
            :class-dir class-dir
            :basis @basis
            :javac-opts ["--release" "17"]}))

(defn uber [_]
  (clean nil)
  (b/copy-dir {:src-dirs ["src" "resources"]
               :target-dir class-dir})
  (compile-java nil)
  (b/compile-clj {:basis @basis
                  :ns-compile '[carbonlink.api]
                  :class-dir class-dir})
  (b/uber {:class-dir class-dir
           :uber-file jar-file
           :basis @basis
           :main 'carbonlink.api.main}))
Running javac --help tells the supported version
--release 
        Compile for the specified Java SE release. Supported releases: 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
Not really grasping where that javac unsuppoerted version issue might stem from. Any help or pointers are welcome!

Alex Miller (Clojure team)21:01:37

I haven’t seen that before, does not at first glance make sense to me. The Java compilation happens in proc, so not sure how it could be any different than what you see reported in the Java version

Alex Miller (Clojure team)21:01:12

Is there any chance this is JRE instead of JDK? Is that even still a thing?

Alex Miller (Clojure team)21:01:51

If you remove the javac options, does it work?

jussi21:01:05

:javac-opts ["-source" "17"
             "-target" "17"]
This worked.

jussi21:01:31

This is a polylith project and not all clojure components contain java-code and this error came from a project that dit not have java at all.

jussi21:01:48

Removing javac-opts also works.

jussi21:01:57

Will settle for this now.