Welcome! Please see the About page for a little more info on how this works.

0 votes
in Leiningen by

Hi,

I have two ClojureScript projects. From the first one (html-ui-lib) I created a JAR file with the following commands and installed it in a local repository:

lein with-profile prod jar
lein localrepo install -r /home/muenkel/soft/Global/clojure-repo target/html-ui-lib-0.1.2-SNAPSHOT.jar html-ui-lib 0.1.2-SNAPSHOT

In the second project (via-trans) I try to use this library. For this purpose I have included the library in the project file. Unfortunately, not all files of the JAR file are installed. What am I doing wrong?

Here is the content of the JAR file:

245 Fri Aug 11 00:02:34 CEST 2023 META-INF/MANIFEST.MF
3268 Fri Aug 11 00:02:34 CEST 2023 META-INF/maven/html-ui-lib/html-ui-lib/pom.xml
3183 Fri Aug 11 00:02:34 CEST 2023 META-INF/leiningen/html-ui-lib/html-ui-lib/project.clj
783 Fri Aug 11 00:02:34 CEST 2023 META-INF/leiningen/html-ui-lib/html-ui-lib/README.md

 0 Fri Aug 11 00:02:32 CEST 2023 META-INF/
 0 Fri Aug 11 00:02:32 CEST 2023 META-INF/maven/
 0 Fri Aug 11 00:02:32 CEST 2023 META-INF/maven/html-ui-lib/
 0 Fri Aug 11 00:02:32 CEST 2023 META-INF/maven/html-ui-lib/html-ui-lib/

158 Fri Aug 11 00:02:32 CEST 2023 META-INF/maven/html-ui-lib/html-ui-lib/pom.properties

 0 Fri Aug 11 00:01:30 CEST 2023 public/
 0 Tue Jul 11 23:15:06 CEST 2023 public/css/

2715 Tue Jul 11 23:15:06 CEST 2023 public/css/style.css
151 Sun Mar 26 21:35:54 CEST 2023 public/test.html

 0 Fri Aug 11 00:02:32 CEST 2023 public/cljs-out/

554 Mon Apr 17 22:11:34 CEST 2023 public/index.html
417 Sat Apr 08 23:03:08 CEST 2023 public/devcards.html

 0 Sat Jul 22 23:08:08 CEST 2023 html_ui_lib/
 0 Wed May 10 20:49:58 CEST 2023 html_ui_lib/util/

1100 Wed May 10 20:49:58 CEST 2023 html_ui_lib/util/limit-lines.cljs
1123 Thu May 04 23:27:52 CEST 2023 html_ui_lib/core.cljs

 0 Tue Jul 18 21:06:24 CEST 2023 html_ui_lib/spec/

272 Sun Jun 04 00:13:12 CEST 2023 html_ui_lib/spec/email-value-specs.cljs
1883 Tue Jul 18 21:06:24 CEST 2023 html_ui_lib/spec/value_specs.cljs
213 Wed Jun 07 23:31:32 CEST 2023 html_ui_lib/spec/text_value_specs.cljs
3871 Wed Jun 07 23:14:28 CEST 2023 html_ui_lib/spec/ui-specs.cljs
267 Wed Jun 07 23:26:06 CEST 2023 html_ui_lib/spec/number_value_specs.cljs
185 Sat May 20 23:56:54 CEST 2023 html_ui_lib/spec/date_value_specs.cljs
178 Wed May 31 00:26:16 CEST 2023 html_ui_lib/spec/drop_down_value_specs.cljs
1545 Mon Jul 17 22:55:08 CEST 2023 html_ui_lib/spec/type_specs.cljs

 0 Tue Jul 18 20:59:58 CEST 2023 html_ui_lib/ui/

3234 Tue Jun 06 21:32:30 CEST 2023 html_ui_lib/ui/input_email.cljs
4298 Tue Jul 18 20:59:58 CEST 2023 html_ui_lib/ui/tree_view.cljs
3361 Wed May 24 22:41:30 CEST 2023 html_ui_lib/ui/input_text.cljs
3420 Sat Jun 03 21:42:24 CEST 2023 html_ui_lib/ui/input_date.cljs
6013 Wed Jun 07 23:35:28 CEST 2023 html_ui_lib/ui/input_number.cljs
2029 Wed Jul 12 22:42:44 CEST 2023 html_ui_lib/ui/core.cljs
396 Fri Apr 07 21:19:26 CEST 2023 html_ui_lib/ui/button.cljs
844 Tue Jul 11 23:13:50 CEST 2023 html_ui_lib/ui/output_boolean.cljs
1127 Wed Jul 12 23:57:34 CEST 2023 html_ui_lib/ui/input_checkbox.cljs
276 Sun Apr 23 22:59:54 CEST 2023 html_ui_lib/ui/grid_container.cljs
603 Thu Jun 08 22:50:00 CEST 2023 html_ui_lib/ui/output_number.cljs
1613 Mon Jul 10 21:58:34 CEST 2023 html_ui_lib/ui/input_radio.cljs
381 Sun Apr 09 00:16:22 CEST 2023 html_ui_lib/ui/table.cljs
1775 Sat Jul 01 22:19:10 CEST 2023 html_ui_lib/ui/drop_down_list.cljs
2789 Wed Jun 28 22:57:44 CEST 2023 html_ui_lib/ui/leaf_template.cljs
313 Thu Jun 08 23:19:22 CEST 2023 html_ui_lib/ui/output_text.cljs
2160 Thu Jul 13 23:36:30 CEST 2023 html_ui_lib/ui/input_password.cljs
519 Wed Jun 07 22:44:34 CEST 2023 html_ui_lib/test_runner.cljs
860 Wed Jun 07 22:57:28 CEST 2023 html_ui_lib/number_value_specs_test.cljs
273 Wed May 24 21:17:16 CEST 2023 html_ui_lib/text_value_specs_test.cljs
1090 Tue May 30 23:24:06 CEST 2023 html_ui_lib/value_specs_test.cljs
7280 Wed Jun 07 23:07:38 CEST 2023 html_ui_lib/ui_specs_test.cljs
2274 Wed May 24 21:37:08 CEST 2023 html_ui_lib/type_specs_test.cljs
305 Wed May 24 23:44:04 CEST 2023 html_ui_lib/drop_down_value_specs_test.cljs
260 Sun Mar 26 21:35:54 CEST 2023 html_ui_lib/core_test.cljs

Here, on the other hand, is the content of the directory with the library. As you can see, only the files of the namespace ui are contained here:

via-trans/resources/public/cljs-out/dev/html_ui_lib/
└── ui
    ├── core.cljs
    ├── core.cljs.cache.json
    ├── core.js
    ├── core.js.map
    ├── input_text.cljs
    └── input_text.js

Here is the project.clj file of html_ui_lib:

(defproject html-ui-lib "0.1.2-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"

        :url "http://www.eclipse.org/legal/epl-v10.html"}

:min-lein-version "2.7.1"
:dependencies [[clj-commons/citrus "3.3.0"]

             [cljs-ajax "0.8.1"]
             [funcool/struct "1.4.0"]
             [org.clojure/clojure "1.10.0"]
             [org.clojure/clojurescript "1.11.60"]
             [rum "0.12.10"]]

;;:deps {io.github.clj-kondo/config-rum-rum {:mvn/version "0.12.10"}}
:global-vars {warn-on-reflection true}
;;:global-vars {asserts false}
:source-paths ["src/cljs" "test/cljs"]
:aliases {"fig:build" ["trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"]

        "fig:min"   ["run" "-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]
        "prod:build" ["run" "-m" "figwheel.main" "-O" "advanced" "-bo" "prod"]}

:profiles {:dev {:dependencies [[com.bhauman/figwheel-main "0.2.18"]

                              [org.slf4j/slf4j-nop "1.7.30"]
                              [com.bhauman/rebel-readline-cljs "0.1.4"]
                              [devcards "0.2.7"]
                              ;; for informing the linter clj-kondo, that the macros
                              ;; defc etc defines symbols
                              [io.github.clj-kondo/config-rum-rum "1.0.0"]]
               :source-paths ["devcards/cljs"]
               :resource-paths ["target"]
               ;; need to add the compiled assets to the :clean-targets
               :clean-targets ^{:protect false} ["target" "resources/public/cljs-out"]
               #_:global-vars #_{*asserts* false}}
         :prod {:dependencies [[com.bhauman/figwheel-main "0.2.18"]]
                :compiler {:optimizations :advanced
                           :pretty-print false}
                :clean-targets ^{:protect false}
                ["target"
                 "resources/public/cljs-out/prod"
                 "resources/public/cljs-out/prod-main.js"]
                :cljsbuild {:builds
                            [{:source-paths ["src/cljs"]
                              :compiler
                              {:output-to "resources/public/cljs-out/prod-main.js"
                               :optimizations :advanced
                               :pretty-print false}
                              :build nil}]}
                :plugins [[lein-cljsbuild "1.1.8"]]}}

:plugins [[com.github.clj-kondo/lein-clj-kondo "0.2.4"]

        [com.fabiodomingues/lein-clj-depend "0.3.0"] ;; Usage: lein clj-depend
        ;; Detects curcular referencies
        [lein-kibit "0.1.8"] ; Code Analyzer: https://github.com/clj-commons/kibit
                                    ; Anounced better code alternatives
                                    ; Usage: lein kibit
                                    ; Automatic: lein auto kibit
                                    ; With replace: lein kibit --replace --interactive
        ])

Here is the project file of via-trans:

(defproject via-trans "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [;;[camel-snake-kebab "0.4.3"] ; Libray used for converting keywords

             [ch.qos.logback/logback-classic "1.4.4"]
             [cljs-ajax "0.8.1"]
             [clj-commons/citrus "3.3.0"]
             ;;[clojure.java-time "1.1.0"]
             ;;[cljc.java-time "RENAMED"]
             [cljc.java-time "0.1.18"]
             [conman "0.9.6"] ; Library used for creating functions from sql
             [cprop "0.1.19"]   ; Configuration
             [devcards "0.2.7"]
             [expound "0.9.0"]
             [funcool/struct "1.4.0"]
             [com.layerware/hugsql "0.5.3"] ; Replacement for conman
             ;[hugsql-adapter-case "0.1.0"] ; case adapter for db table columns 
             [html-ui-lib "0.1.2-SNAPSHOT"]
             [json-html "0.4.7"]
             [luminus-transit "0.1.5"]
             [luminus-undertow "0.1.18"]
             [luminus/ring-ttl-session "0.3.3"]
             [org.mariadb.jdbc/mariadb-java-client "1.1.5"]
             ;;[mysql/mysql-connector-java "8.0.18"]
             [markdown-clj "1.11.3"]
             [metosin/muuntaja "0.6.8"]
             [metosin/reitit "0.5.18"]
             [metosin/ring-http-response "0.9.3"]
             [mount "0.1.16"]
             [nrepl "1.0.0"]
             [org.clojure/clojure "1.11.1"]
             [org.clojure/clojurescript "1.11.60"]
             [org.clojure/tools.cli "1.0.214"]
             [org.clojure/tools.logging "1.2.4"]
             [org.webjars.npm/bulma "0.9.4"]
             [org.webjars.npm/material-icons "1.10.8"]
             [org.webjars/webjars-locator "0.45"]
             [org.webjars/webjars-locator-jboss-vfs "0.1.0"]
             [ring-webjars "0.2.0"]
             [ring/ring-core "1.9.6"]
             [ring/ring-defaults "0.3.4"]
             [rum "0.12.10"]
             [selmer "1.12.55"]]

:min-lein-version "2.0.0"
:source-paths ["src/clj" "src/cljc" "src/cljs" "devcards/cljs"]
:test-paths ["test/clj" "test/cljc" "test/cljs"]
:resource-paths ["resources" "target"]
:clean-targets ^{:protect false} ["target" "resources/public/cljs-out"]
:target-path "target/%s/"
:main ^:skip-aot via-trans.core
:plugins []
:profiles
{:uberjar {:omit-source true

         :aot :all
         :uberjar-name "via-trans.jar"
         :source-paths ["env/prod/clj" ]
         :resource-paths ["env/prod/resources"]}

:dev [:project/dev :profiles/dev]
:test [:project/dev :project/test :profiles/test]
:project/dev {:jvm-opts ["-Dconf=dev-config.edn" ]

              :dependencies [[com.bhauman/figwheel-main "0.2.18"]
                             [com.bhauman/rebel-readline-cljs "0.1.4"]
                             [org.clojure/tools.namespace "1.3.0"]
                             [pjstadig/humane-test-output "0.11.0"]
                             [prone "2021-04-23"]
                             [ring/ring-devel "1.9.6"]
                             [ring/ring-mock "0.4.0"]]
              :plugins      [[com.jakemccrary/lein-test-refresh "0.24.1"]
                             [jonase/eastwood "1.2.4"]
                             ;;[cider/cider-nrepl "0.28.4"] ; ist in .lein/profiles.clj
                             ]   
              :source-paths ["env/dev/clj" ]
              :resource-paths ["env/dev/resources" "target"]
              :repl-options {:init-ns user
                             :timeout 120000}
              :injections [(require 'pjstadig.humane-test-output)
                           (pjstadig.humane-test-output/activate!)]}

:project/test {:jvm-opts ["-Dconf=test-config.edn" ]

              :resource-paths ["env/test/resources"] }

:profiles/dev {}
:profiles/test {}})

by
You missed describing what the actual problem is. This all looks like it should, so kinda hard to infer a problem from that.
by
The problem is, that not all files of the jar file are installed in via-trans/resources/public/cljs-out/dev/html_ui_lib/ (look at the directory listing in my post - behind the content listing of the jar file). Only the namespace html-ui-lib/ui and, for example, not the namespace html-ui-lib/spec. But since the files in html-ui-lib/ui need the files from html-ui-lib/spec, there are compile errors.

1 Answer

0 votes
by

Your setup is uncommon, therefore it is kinda hard to figure out what you expect to happen or why you'd want typically development only files in the .jar.

In common Clojure(Script) setups libraries only contain their source code, and no compiled artifacts. Actual projects then use those libraries to build what they need.

There can still be CLJS builds in the library as well, but those would only be relevant for the development of that library, and not part of the actual published outputs.

If for some reason you don't want this and prefer to keep the build in the library, then the only relevant file the project should include in the .jar is the .js file produced by the prod build. Which is likely defined in a prod.edn in the project. It likely only produces one output file. The files you complained about missing are development files, and should no longer be relevant.

Your project also seems to be a little stitched together since there are still remnants of what probably used to be lein-cljsbuild config, yet also some newer figwheel.main references. You probably want to clean that up so it is easier to figure out what is actually going on.

I'm also not sure about the use of lein-localrepo. A simpler lein install should achieve the same, if the goal is using the local installed library from the project. Not sure what else localrepo does exactly.

by
The localrepo plugin lets you install an arbitrary JAR file under a specific set of coordinates, intended to help you use libraries that either exist only as plain downloads (not in a Maven repo) or as source projects with arbitrary build processes (so you have to d/l and build your own JAR). Using it instead of lein install seems... very peculiar to me.
by
I think the unusual things in the project.clj file are due to my ignorance rather than intent. Also, for the production profile prod, I experimented with both cljsbuild and figwheel.

I did the development with figwheel.main and thought for production I would have to use the normal clojurescript compiler cljsbuild.
When I use figwheel to produce an optimized javascript file not all namespaces are included as opposed to using cljsbuild.

But if I understood you correctly, only the cljs files should be included in the JAR file anyway - right?
Then the command `lein with-profile prod jar` alone should be enough to create the JAR file - right?
As you can see at the top of my post, the JAR file also contains only the cljs and no js files.
by
Just to be clear. `lein install` will produce a jar and install it locally in `~/.m2`, making it accessible to other projects. You don't need to manually create the jar, nor use localrepo. Yes, only including the .cljs files is the standard way of doing things. It does however requiring adding or moving the build setups to the project. Figwheel not including everything I presume is due to you maybe not properly requiring things in your code, i.e. missing (ns ... (:require ...)).
by
Thanks for the hint. I didn't know this. I've now reinstall the html-ui-lib project with `lein install`, but the error is still there.  Only the Clojurescript files ui/core.cljs and ui/input_text.cljs are copied (installed) in the via-trans-project and I don't understand why.

Is there any meta file, which I must fill with information about the clojurescript files in the jar?
by
There again is an expectation I cannot quite follow. install will copy the .jar into the ~/.m2 repository directories. It will not copy anything into the via-trans project. Why are you expecting files to be copied to the via-trans project? There is no extra configuration for .jar files, they only need to contain the files. Which seems to be the case based on your initial post. You project also needs to have a dependency on the library, which appears to be missing in either case? There should be a [html-ui-lib "0.1.2-SNAPSHOT"] in your project :dependencies.
by
The dependency entry [html-ui-lib "0.1.2-SNAPSHOT"] exist in the project.clj file of via-trans.

After running the emacs command cider-jack-in-cljs with the repl type figwheel-main and the build dev, I got the following compile error:
``` clojurescript
[Figwheel:WARNING] Compile Exception   resources/public/cljs-out/dev/html_ui_lib/ui/input_text.cljs   line:7  column:5

  No such namespace: html-ui-lib.spec.ui-specs, could not locate html_ui_lib/spec/ui_specs.cljs, html_ui_lib/spec/ui_specs.cljc, or JavaScript source providing "html-ui-lib.spec.ui-specs" (Please check that namespaces with dashes use underscores in the ClojureScript file name) in file resources/public/cljs-out/dev/html_ui_lib/ui/input_text.cljs

   2    (:require
   3     [citrus.core :as citrus]
   4     [rum.core :as rum]
   5     [html-ui-lib.ui.core :refer [get-event-value-save-cursor!
   6                                  set-cursor-pos-mixin]]
   7     [html-ui-lib.spec.ui-specs :as us]
          ^---
   8     [cljs.spec.alpha :as s]))
```
The complained missing file "html_ui_lib/spec/ui_specs.cljs" is in the jar file but it is not in the directory "resources/public/cljs-out/dev/html_ui_lib/". There is only the ui directory. That's the reason why I'm assuming, that the compiler copies the content of the dependencies to "resources/public/cljs-out/dev", but did not do so completely in the case of html-ui-lib.
by
The error it is complaining about is that the file actually has the wrong name. Remember that filenames are supposed to replace - with _. And based on your initial post the file is called html_ui_lib/spec/ui-specs.cljs, note the last -. Replace that and you should be good.

I don't know why figwheel is using the resources/public folder as a reference, that is a very misleading and not the source of the actual file that is being used. But now I get why you were confused about file locations.
by
Thank you very much for your help.

The reason of the problems where indeed the underscores in the filenames. I've known, that in Clojure / Clojurescript the filenames must have underscores instead of dashes. But as an old Lisp programmer I'm always using dashes instead of underscores in filenames without thinking about it.
But however, I tested my code in html-lib-ui with defcard and tests without any problems. It seems to me, that Clojurescript has not as much problems with dashes in filenames than Clojure.
Are there any linters or packages for the Emacs to get a warning about dashes in filenames?
...