clojureleiningen

Leiningen how to include dependency into result jar file


(defproject dumortierite "0.1.0-SNAPSHOT"
 
  ;; omitted...

  :dependencies [
                 [com.github.freeze-dolphin/clamp "4ddd923dcb" :scope "compile"]

                 [org.clojure/clojure "1.11.1" :scope "provided"]
                 [io.papermc.paper/paper-api "1.19.3-R0.1-SNAPSHOT" :scope "provided"]
                 [com.github.StarWishsama/Slimefun4 "2023.02" :scope "provided"]
                ])

I've added 4 dependencies, and I want to include only
[com.github.freeze-dolphin/clamp "4ddd923dcb" :scope "compile"]
in the build result jar

if using lein uberjar, it will contain all of these 4 deps in the jar.

i know this could be done by using shade in maven, but how in leiningen?


I've tried below:

:dependencies [[com.github.freeze-dolphin/clamp "4ddd923dcb"]]
  :profiles {:dev
             {:dependencies
              [
               [com.github.freeze-dolphin/clamp "4ddd923dcb" :scope "compile"]
               ]}
             :provided
             {:dependencies
              [
               [org.clojure/clojure "1.11.1" :scope "provided"]
               [io.papermc.paper/paper-api "1.19.3-R0.1-SNAPSHOT" :scope "provided"]
               [com.github.StarWishsama/Slimefun4 "2023.02" :scope "provided"]
               ]}}

but in jar, no deps is contained.
and in uberjar, everything is contained...


Solution

  • As a workaround, you can use :uberjar-exclusions in your project.clj with a vector of regular expressions that will be used to match the filenames in the project. Any match will cause the file not to be packed in the Uberjar.

    I tested it on a sample project with the following dependencies:

      :dependencies [[org.clojure/clojure "1.11.1" :scope "provided"]
                     [commons-codec/commons-codec "1.15"]]
    

    To exclude the files from commons-codec from the Uberjar, I used:

    :profiles {:uberjar {:aot :all
                         :uberjar-exclusions [#"org/apache/commons/codec"
                                              #"META-INF/maven/commons-codec"]
                         :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}}
    

    The original example is in the sample project.clj from Leiningen.