lein-ring icon indicating copy to clipboard operation
lein-ring copied to clipboard

lein ring uberjar fails with "Key must be integer"

Open paulbutcher opened this issue 11 years ago • 15 comments

I've just upgraded a project from lein-ring 0.8.11 to 0.8.12. Now, when running lein ring uberjar, I get:

java.lang.IllegalArgumentException: Key must be integer
 at clojure.lang.APersistentVector.assoc (APersistentVector.java:335)
    clojure.lang.APersistentVector.assoc (APersistentVector.java:18)
    clojure.lang.RT.assoc (RT.java:702)
    clojure.core$assoc.invoke (core.clj:187)
    clojure.core$assoc_in.invoke (core.clj:5685)
    clojure.core$assoc_in.invoke (core.clj:5684)
    clojure.core$assoc_in.invoke (core.clj:5684)
    clojure.lang.AFn.applyToHelper (AFn.java:160)
    clojure.lang.AFn.applyTo (AFn.java:144)
    clojure.core$apply.invoke (core.clj:626)
    clojure.core$vary_meta.doInvoke (core.clj:640)
    clojure.lang.RestFn.invoke (RestFn.java:464)
    leiningen.ring.uberjar$no_uberjar_clean.invoke (uberjar.clj:12)
    leiningen.ring.uberjar$uberjar.invoke (uberjar.clj:20)
    clojure.lang.AFn.applyToHelper (AFn.java:154)
    clojure.lang.AFn.applyTo (AFn.java:144)
    clojure.core$apply.invoke (core.clj:626)
    leiningen.ring$ring.doInvoke (ring.clj:26)
    clojure.lang.RestFn.invoke (RestFn.java:425)
    clojure.lang.Var.invoke (Var.java:383)
    clojure.lang.AFn.applyToHelper (AFn.java:156)
    clojure.lang.Var.applyTo (Var.java:700)
    clojure.core$apply.invoke (core.clj:626)
    leiningen.core.main$partial_task$fn__4230.doInvoke (main.clj:234)
    clojure.lang.RestFn.applyTo (RestFn.java:139)
    clojure.lang.AFunction$1.doInvoke (AFunction.java:29)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.core$apply.invoke (core.clj:626)
    leiningen.core.main$apply_task.invoke (main.clj:281)
    leiningen.core.main$resolve_and_apply.invoke (main.clj:287)
    leiningen.core.main$_main$fn__4295.invoke (main.clj:357)
    leiningen.core.main$_main.doInvoke (main.clj:344)
    clojure.lang.RestFn.invoke (RestFn.java:421)
    clojure.lang.Var.invoke (Var.java:383)
    clojure.lang.AFn.applyToHelper (AFn.java:156)
    clojure.lang.Var.applyTo (Var.java:700)
    clojure.core$apply.invoke (core.clj:624)
    clojure.main$main_opt.invoke (main.clj:315)
    clojure.main$main.doInvoke (main.clj:420)
    clojure.lang.RestFn.invoke (RestFn.java:457)
    clojure.lang.Var.invoke (Var.java:394)
    clojure.lang.AFn.applyToHelper (AFn.java:165)
    clojure.lang.Var.applyTo (Var.java:700)
    clojure.main.main (main.java:37)

I see the same behaviour with both Leiningen 2.4.3 and 2.5.0, both locally and when building on Travis. Downgrading to lein-ring 0.8.11 fixes the problem. Seems to be related to https://github.com/weavejester/lein-ring/commit/4acd3170429f8a42f3aa4f7fa90769af2950e01c?

paulbutcher avatar Oct 11 '14 23:10 paulbutcher

Can you provide your project file?

weavejester avatar Oct 12 '14 00:10 weavejester

Sure:

(defproject annotator "0.1"
  :source-paths ["src-clj"]
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [org.clojure/clojurescript "0.0-2371"]
                 [org.clojure/core.rrb-vector "0.0.11"]
                 [reagent "0.4.2"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [compojure "1.2.0"]
                 [enlive "1.1.5"]
                 [cljs-ajax "0.3.3"]
                 [com.taoensso/timbre "3.3.1"]]
  :plugins [[lein-ancient "0.5.5"]
            [lein-cljsbuild "1.0.3"]
            [lein-ring "0.8.11"]
            [com.cemerick/clojurescript.test "0.3.1"]
            [lein-zip "0.1.0"]]
  :profiles {:production {:resource-paths ["target/production"]
                          :source-paths ["production/src-clj"]}
             :dev {:resource-paths ["target/dev"]
                   :source-paths ["dev/src-clj"]}
             :uberjar [:production {:aot :all}]}
  :cljsbuild {:builds {:dev {:source-paths ["src-cljs"]
                             :compiler {:output-dir "target/dev/public/js"
                                        :output-to "target/dev/public/js/main.js"
                                        :optimizations :whitespace
                                        :pretty-print true
                                        :source-map "target/dev/public/js/main.map"}}
                       :production {:source-paths ["src-cljs"]
                                    :compiler {:output-to "target/production/public/js/main.min.js"
                                               :optimizations :advanced
                                               :externs ["react/react.js"
                                                         "externs/jquery-1.9.js"
                                                         "externs/twitter-bootstrap.js"]
                                               :closure-warnings {:check-useless-code :off}
                                               :pretty-print false}}
                       :test {:source-paths ["src-cljs" "test-cljs"]
                              :compiler {:output-to "target/test/js/unit-test.js"
                                         :preamble ["reagent/react.js"]
                                         :optimizations :whitespace
                                         :pretty-print true}}}
              :test-commands {"unit-tests" ["phantomjs" :runner
                                            "resources/private/bind-polyfill.js"
                                            "target/test/js/unit-test.js"]}}
  :zip ["Dockerfile" 
        "target/annotator-0.1-standalone.jar"]
  :ring {:init annotator.core/init
         :handler annotator.core/handler})

paulbutcher avatar Oct 12 '14 09:10 paulbutcher

Okay, I see the issue. Looks like the function for extending the uberjar profile needs to be smarter.

It seems strange that there isn't a function in Leiningen to extend profiles, but I haven't been able to find one.

weavejester avatar Oct 12 '14 11:10 weavejester

Cool - thanks for the rapid response.

paulbutcher avatar Oct 12 '14 11:10 paulbutcher

Can you try using "0.8.13-SNAPSHOT" and see if your problem is fixed?

weavejester avatar Oct 12 '14 13:10 weavejester

It fixes the error, yes. But unfortunately it doesn't look like the profiles have been merged correctly, so the resulting uberjar is broken :-(

I've created a cut-down version of my project that demonstrates the issue:

https://github.com/paulbutcher/lein-ring-issue

With lein-ring 0.8.11, I can build and run uberjar like this:

lein cljsbuild once
lein ring uberjar
java -jar target/annotator-0.1-standalone.jar

If I then navigate to http://localhost:3000 everything's fine. I can see that the compiled ClojureScript is included in the JAR:

$ unzip -l target/annotator-0.1-standalone.jar | grep main.min.js
   119332  10-12-14 14:57   public/js/main.min.js

If, on the other hand, I use lein-ring 0.8.13-SNAPSHOT, the build appears to work, but the navigating to http://localhost:3000 gives me a 404. I can see that the compiled ClojureScript is not included in the JAR:

$ unzip -l target/annotator-0.1-standalone.jar | grep main.min.js

So it looks as though the custom resource-paths defined in the :production profile aren't making it to the merged :uberjar profile?

paulbutcher avatar Oct 12 '14 14:10 paulbutcher

This is significantly more difficult than it should be. All we're trying to do is override a single key that Leiningen sets by default. There has to be an easier way than manually trying to reverse Leiningen's profile syntax.

I'll check on the Leiningen mailing list, see if they have any ideas.

weavejester avatar Oct 12 '14 14:10 weavejester

I've asked on the mailing list and done some more experiments. This might be a bug in Leiningen, since for some reason:

:uberjar {:aot :all}

Is different to:

:foo {}
:uberjar [:foo {:aot :all}]

I had assumed they were the same, but it looks like they're not.

weavejester avatar Oct 12 '14 17:10 weavejester

Ah - sounds like progress. Forgive the silly question, but on which mailing list is this conversation taking place? I can't see it in the Librelist archive:

http://librelist.com/browser/leiningen/

paulbutcher avatar Oct 12 '14 17:10 paulbutcher

Odd... Does the archive take a while to update? That's where I've posted to.

weavejester avatar Oct 12 '14 17:10 weavejester

I guess it must :) Probably a good incentive for me to actually subscribe...

paulbutcher avatar Oct 12 '14 17:10 paulbutcher

it's visible now:

http://librelist.com/browser//leiningen/2014/10/12/injecting-files-into-jars-via-plugin/

Not sure what the answer is, mind...

cdpjenkins avatar Oct 12 '14 17:10 cdpjenkins

It looks like this is at least partially caused, or at least complicated, by https://github.com/technomancy/leiningen/issues/1694, which is fixed in Lein master, but affects version 2.5.0.

For the time being, it looks like composite profiles for uberjars don't work well.

weavejester avatar Oct 12 '14 19:10 weavejester

While we're playing in this space, could a fix for this also be (or help with) a fix for https://github.com/weavejester/lein-ring/issues/116?

paulbutcher avatar Oct 12 '14 23:10 paulbutcher

That seems like an entirely unrelated bug.

weavejester avatar Oct 12 '14 23:10 weavejester