Fork me on GitHub
#clojure
<
2023-03-11
>
emccue23:03:48

Has anyone gotten clojure w/deps.edn running on heroku recently? I tried the blank project.clj trick and the build script runs, but for whatever reason doesn't see my uberjar.clj file

practicalli-johnny00:03:55

uberjar.clj file? Do I assume you mean the built project-name.jar uberjar file? I used to use the following customised Leiningen build for Clojure CLI projects previously - but since then have cancelled all my Heroku accounts (Note: I used to work for Heroku 2012-2017) https://practical.li/clojure-web-services/projects/status-monitor-deps/deployment-via-ci/ (this content will be deprecated soon) Rather than the build from source approach on Heroku, a docker image could be created locally and deployed on Heroku. Or if possible to change your deployment service, consider https://render.com/ (there are other services too) (Note: I dont work for any cloud service company)

emccue00:03:15

i mean i have a build alias which just runs this file

emccue00:03:48

(ns uberjar
  (:require [clojure.tools.build.api :as b]
            [org.corfield.build :as bb]
            [clojure.java.shell :as sh]))

(defn -main
  "Builds an uberjar"
  [& _]
  (let [tailwind-run-result (sh/sh "bb" "tailwind")]
    (when (not= 0 (:exit tailwind-run-result))
      (binding [*out* *err*]
        (println (:err tailwind-run-result)))))

  (let [class-dir "target/classes"
        uber-file "target/standalone.jar"
        opts      {:class-dir     class-dir
                   :compile-opts  {:direct-linking false}
                   :main          'proj.main
                   :uber-file     uber-file
                   :exclude       ["license(.)*"]
                   :src-dirs      ["src"]
                   :resource-dirs ["resources" "prod"]}]
    (b/delete {:path class-dir})
    (bb/uber opts)
    (println "Uberjar is built.")
    opts

    (shutdown-agents)))

practicalli-johnny00:03:02

Was a bin/build script added to the project with a command that would run the relevant code from the uberjar namespace to create the uberjar on Heroku? This would be the same command run locally to create the uberjar file?

p-himik11:03:41

I'm running a deps.edn project on Heroku, but from sources, and with a custom buildpack. :) So probably not useful to you at all.

emccue15:03:15

yep - bin/build just does clojure -M:build

emccue15:03:22

and it is being detected and run

emccue15:03:32

getting new failure now

emccue15:03:34

remote:        java.lang.NullPointerException
remote:        	at clojure.tools.deps.alpha.util.maven$make_session.invokeStatic(maven.clj:221)
remote:        	at clojure.tools.deps.alpha.util.maven$make_session.invoke(maven.clj:216)
remote:        	at clojure.tools.deps.alpha.extensions.maven$read_descriptor$fn__1047.invoke(maven.clj:111)
remote:        	at clojure.tools.deps.alpha.util.session$retrieve$reify__356.apply(session.clj:28)
remote:        	at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
remote:        	at clojure.tools.deps.alpha.util.session$retrieve.invokeStatic(session.clj:25)
remote:        	at clojure.tools.deps.alpha.util.session$retrieve.invoke(session.clj:18)
remote:        	at clojure.tools.deps.alpha.util.session$retrieve_local.invokeStatic(session.clj:35)
remote:        	at clojure.tools.deps.alpha.util.session$retrieve_local.invoke(session.clj:30)
remote:        	at clojure.tools.deps.alpha.extensions.maven$read_descriptor.invokeStatic(maven.clj:111)
remote:        	at clojure.tools.deps.alpha.extensions.maven$read_descriptor.invoke(maven.clj:106)
remote:        	at clojure.tools.deps.alpha.extensions.maven$eval1074$fn__1075.invoke(maven.clj:146)
remote:        	at clojure.lang.MultiFn.invoke(MultiFn.java:244)
remote:        	at clojure.tools.deps.alpha$expand_deps$children_task__662$fn__664$fn__665.invoke(alpha.clj:405)
remote:        	at clojure.tools.deps.alpha.util.concurrent$submit_task$task__298.invoke(concurrent.clj:35)
remote:        	at clojure.lang.AFn.call(AFn.java:18)
remote:        	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
remote:        	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
remote:        	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
remote:        	at java.lang.Thread.run(Thread.java:750)
remote:        Execution error (NullPointerException) at clojure.tools.deps.alpha.util.maven/make-session (maven.clj:221).
remote:        null
remote:
remote:        Full report at:
remote:        /tmp/clojure-6079687224478408742.edn
remote:  !     Failed to build.
remote:  !     Push rejected, failed to compile Clojure app.
remote:
remote:  !     Push failed
remote:  !

p-himik15:03:44

Oh, another tidbit - I ended up being fed up with fiddling with building on Heroku whenever my build process would require something new. Ended up switching to Docker images (although with Podman instead of Docker), and definitely won't look back at pure source-based deployment. WRT that error - there should be a way to print that report as well. I think you can add -J-Dclojure.main.report=stderr to the clojure command to do that.

Zmicier Misiuk22:03:26

I was able to run deps.edn project with this buikdpack https://github.com/andersmurphy/heroku-buildpack-clojure-tools.git and bin/build . It's important to set right versions of Clojure and jdk for app by system.properties and CLOJURE_CLI_VERSION env variable.

emccue16:03:04

upgrading the jdk version from 8 mysteriously solved everything. not gonna think on it too hard

catjam 2
Zmicier Misiuk16:03:37

What version of jdk you use now?

emccue00:03:13

i bumped to 19 from the default of 8