depstar

Discussion around https://github.com/seancorfield/depstar
timo 2020-09-23T09:29:59.000500Z

Hi 👋

timo 2020-09-23T09:32:07.002700Z

I am currently setting up CI for a CLJ/CLJS library and CLJS is new to me. The uberjar built is 30MB. Usually I was building and uploading uberjars to clojars. But the project is quite small and shouldn't be 30MB in size. When does one use uberjars and when does one use thinjars?

timo 2020-09-23T09:36:50.003300Z

I mean there supposedly is no AOT-compilation happening as far as I understand it.

practicalli-john 2020-09-23T11:57:44.003400Z

Short answer: deploy uberjars, publish jars When deploying to a server / container, the uberjar has everything it needs, except for the Java runtime. So its possible to run the uberjar just using a java command (essentially what the Clojure CLI tool wraps). Clojars are a collection of library dependencies, each of which can be added to another project. When adding a library to a project, any dependencies the library contains will be downloaded when running the project. Therefore its is encouraged that libraries have no more dependencies that really needed. Uberjars shouldnt be published to Clojars as this would be very inefficient and a potential cause of dependency conflicts.

timo 2020-09-23T12:06:23.003600Z

alright, good to know. Thank you very much!

timo 2020-09-23T12:06:48.003800Z

lein deploy just did what it did. now I am using depstar and was thinking about this the first time

practicalli-john 2020-09-23T12:12:17.004Z

Yes, I have found using the Clojure CLI tools and the community tools like depstar and clj-new has given me an opportunity for greater understanding.

seancorfield 2020-09-23T16:10:46.004400Z

@timok hf.depstar.jar for publishing to Clojars ("thin" JAR), hf.depstar.uberjar for deploying to "production" as an executable ("uber" JAR).

seancorfield 2020-09-23T16:11:17.004600Z

The thing that makes the uberjar so much bigger is the entire Clojure compiler/runtime has to be included (plus any other libraries you depend on).

seancorfield 2020-09-23T16:13:06.004800Z

(! 657)-> clojure -M:new app timo/example
Generating a project called example based on the 'app' template.
(! 658)-> cd example/
(! 659)-> clojure -M:uberjar
Compiling timo.example ...
Building uber jar: example.jar
Processing pom.xml for {timo/example {:mvn/version "0.1.0-SNAPSHOT"}}
(! 660)-> ls -l example.jar 
-rw-------  1 sean  staff  4688835 Sep 23 09:12 example.jar
Essentially "Hello World" is just over 4.5MB with nothing but Clojure itself added.

seancorfield 2020-09-23T16:13:26.005Z

(! 661)-> java -jar example.jar 
Hello, World!

seancorfield 2020-09-23T16:31:23.005200Z

By contrast, a minimal library project and "thin" JAR:

(! 664)-> clojure -M:new lib timo/example
Generating a project called example based on the 'lib' template.
The lib template is intended for library projects, not applications.
(! 665)-> cd example/
(! 666)-> clojure -M:jar
Building thin jar: example.jar
Processing pom.xml for {timo/example {:mvn/version "0.1.0-SNAPSHOT"}}
(! 667)-> ls -l example.jar 
-rw-------  1 sean  staff  2258 Sep 23 09:30 example.jar
Just 2K for the source of the project itself (and some metadata in the JAR)

timo 2020-09-23T19:00:59.005400Z

now I have a good understanding of it. thanks for the answers!