Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lein uberjar doesn't remove prior version of compiled JS, shipping dev code #414

venantius opened this issue Sep 7, 2015 · 11 comments


Copy link

venantius commented Sep 7, 2015

I'm relatively new to Cljs, but not to Clojure, and this behavior has been confusing to me. I have a project.clj as follows:

(defproject clip "0.1.0-SNAPSHOT"
  :description ""
  :url ""
  :license {:name "Eclipse Public License"
            :url ""}
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [org.clojure/tools.logging "0.3.1"]
                 [org.slf4j/slf4j-log4j12 "1.7.12"]
                 [org.clojure/clojurescript "1.7.48"]
                 [org.omcljs/om "0.9.0"]
                 [korma "0.4.2"]
                 [ragtime "0.5.2"]

                 [ring "1.4.0"]
                 [aleph "0.4.0"] ;; let's try Aleph
                 [ring/ring-defaults "0.1.5"]
                 [compojure "1.4.0"]

                 [prismatic/schema "1.0.1"]
                 [environ "1.0.0"]
                 [clj-time "0.11.0"]

                 [org.postgresql/postgresql "9.4-1202-jdbc4"]

  :plugins [[lein-cljsbuild "1.0.5"]
            [lein-environ "1.0.0"]]

  :main clip.core
  :source-paths ["src/clj"]
  :test-paths ["test/clj"]
  :min-lein-version "2.5.0"

  :cljsbuild {:builds {:app {:source-paths ["src/cljs"]
                             :compiler {:output-to     "resources/public/js/app.js"
                                        :output-dir    "target/out"
                                        :source-map    "resources/public/js/"
                                        :preamble      ["react/react.min.js"]
                                        :optimizations :none
                                        :main "clip.core"
                                        :asset-path "js/out"
                                        :pretty-print  true}}}}

  :profiles {:dev
             {:env {:environment "dev"
                    :database-url "postgres://localhost:5432/clip"
                    :port "8080"
                    :is-dev true}

              :plugins [[jonase/eastwood "0.1.4"]
                        [lein-figwheel "0.3.9"]]

              :eastwood {:exclude-linters [:deprecations]}

              :figwheel {:http-server-root "public"
                         :css-dirs ["resources/public/css"]
                         :nrepl-port 7002
                         :ring-handler clip.core/app}

              :cljsbuild {:test-commands {"test"
                          :builds {:app {:figwheel true}
                                   :test {:source-paths ["src/cljs" "test/cljs"]
                                          :compiler {:output-to     "resources/public/js/app_test.js"
                                                     :output-dir    "resources/public/js/test"
                                                     :source-map    "resources/public/js/"
                                                     :preamble      ["react/react.min.js"]
                                                     :optimizations :whitespace
                                                     :pretty-print  false}}}}}

             {:env {:environment "test"
                    :database-url "postgres://localhost:5432/clip_test"
                    :port "8080"
                    :session-key "antarctica--bear"}
              :plugins [[jonase/eastwood "0.1.4"]]
              :jvm-opts [""]}

             {:env {:environment "staging"}}

             {:env {:environment "production"}}

             :uberjar {:hooks [leiningen.cljsbuild]
                       :env {:production true}
                       :omit-source true
                       :aot :all
                       :cljsbuild {:builds {:app
                                            {:jar true
                                             {:optimizations :advanced
                                              :pretty-print false}}}}}}

If I've been running figwheel for a while in development, but I stop and then run lein uberjar, my ClojureScript code is not re-compiled for the different uberjar profile, meaning my uberjar now ships with application code that tries to open a figwheel connection.

If I manually delete /resources/public/js/app.js and trigger a re-compile by running lein with-profile uberjar cljs build once, then run lein uberjar, the jar file has the correct javascript file (no figwheel connection attempted).

Copy link

venantius commented Sep 30, 2015

This issue was resolved for me by the steps detailed in #366 (comment)

@venantius venantius reopened this Oct 1, 2015
Copy link

venantius commented Oct 1, 2015

I lied. Cljsbuild still doesn't overwrite existing compiled js during an uberjar build.

Copy link

mneise commented Oct 1, 2015

Taking a look at this now 😉

Copy link

mneise commented Oct 1, 2015

Not able to reproduce this yet. Could you maybe provide a minimal repository to reproduce this issue?

Copy link

venantius commented Oct 11, 2015

So, after a bit of work, my running hypothesis is that Cljsbuild won't try to re-compile js if it finds the existing file, in this case "resources/public/js/app.js"

I can work on putting together a minimal test case to further drill in on this, but by looking at the actual files that my uberjar contained as I tweaked various aspects of the build system the only thing that caused files to be included in the uberjar was nuking the entirety of the resources/public/js folder, and critically that file.

Copy link

psalaberria002 commented Nov 29, 2015

@venantius Did you find any solution to this issue? Indeed, removing "resources/public/js/app.js" does the trick. However, this is not an elegant solution at all.

Copy link

venantius commented Nov 30, 2015

@psalaberria002 The other thing I found that helped was adding the build path to leiningen's :clean-targets

Copy link

mneise commented Dec 4, 2015

The reason it doesn't recompile is that lein-cljsbuild only recompiles if the sources have been modified since the last build. I'm currently not aware of another solution, other than running lein clean or using different output files for different builds.

I think for 2.0 I will probably remove this behaviour, since ClojureScript itself is pretty good when it comes to incremental builds.

Copy link

venantius commented Dec 4, 2015

That's interesting. I think using the plugin to force cleaning of the compilation target directory prior to uberjar compilation is probably the desirable / "expected" behavior here.

Copy link

venantius commented Dec 4, 2015

Anyways, happy that we've been able to nail this down as something warranting investigation rather than a "can't-reproduce" ^.^

Copy link

raxod502 commented Jul 21, 2017

I have the same problem. If I change my cljsbuild configuration, then I have to remove app.js in order to force lein cljsbuild once to do anything.

@mneise mneise modified the milestones: 1.1.7, 2.0.0, 1.1.8 Jul 30, 2017
@mneise mneise removed this from the 1.1.8 milestone Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

4 participants