create multiple uberjars in leiningen
Asked Answered
F

2

13

I want to create a number of uberjars with different main entrypoints from a single codebase. I see you can specify the main namespace as an argument to lein uberjar but I don't see a way to specify the resulting filename or path, so they'll just overwrite one another. Is there a way to override the output filename or path from the command line?

Or is there a better way of doing this? Have separate project files that all reference a central "library" project? If so, what would the physical structure of this look like and how to get it to build?

Flem answered 12/10, 2013 at 12:57 Comment(0)
U
22

You can use multiple Leiningen profiles to accomplish what you are talking about.

(defproject project1 "0.1.0-SNAPSHOT"
  :description "Something Amazing!"
  :dependencies [[org.clojure/clojure "1.5.1"]]
  :profiles {:v1 {:main project1.core1
                  :uberjar-name "uberjar1.jar"}
             :v2 {:main project1.core2
                  :uberjar-name "uberjar2.jar"}
             :v3 {:main project1.core3
                  :uberjar-name "uberjar3.jar"}})

And, you can build them with:

$ lein with-profile v1:v2:v3 uberjar
Ungrounded answered 12/10, 2013 at 15:4 Comment(2)
I'm noticing that the resulting jar filename isn't modified by the :uberjar-name option. Looks like :name has to be set in the profile instead in order to produce different named jar files.Ocher
There is an issue with Leiningen 2.5.0 around it ignoring the :uberjar-name inside profiles. It is scheduled to be resolved with Leiningen 2.5.2. github.com/technomancy/leiningen/issues/1718Ungrounded
Q
1

Here is an annotated reference source where you can find an option for specifying a name of your output jar or uberjar file and any other options that may be set in a project.clj file.

;;; Jar Output
;; Name of the jar file produced. Will be placed inside :target-path.
;; Including %s will splice the project version into the filename.
:jar-name "sample.jar"
;; As above, but for uberjar.
:uberjar-name "sample-standalone.jar"
Quartzite answered 4/11, 2017 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.