weavejester / lein-ring

Ring plugin for Leiningen
Eclipse Public License 1.0
502 stars 100 forks source link

lein ring uberjar fails with "Key must be integer" #131

Open paulbutcher opened 9 years ago

paulbutcher commented 9 years ago

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?

weavejester commented 9 years ago

Can you provide your project file?

paulbutcher commented 9 years ago

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})
weavejester commented 9 years ago

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.

paulbutcher commented 9 years ago

Cool - thanks for the rapid response.

weavejester commented 9 years ago

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

paulbutcher commented 9 years ago

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?

weavejester commented 9 years ago

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 commented 9 years ago

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.

paulbutcher commented 9 years ago

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/

weavejester commented 9 years ago

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

paulbutcher commented 9 years ago

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

cdpjenkins commented 9 years ago

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

weavejester commented 9 years ago

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.

paulbutcher commented 9 years ago

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?

weavejester commented 9 years ago

That seems like an entirely unrelated bug.