Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #902 from hyPiRion/uberjar-compile-after-aot-calcu…

…lations

Make jar accept alternative main class
  • Loading branch information...
commit 18ed0590ff36a6ada676c6f16421e3647e9777b1 2 parents e01a198 + ce29130
Michael Klishin authored
Showing with 28 additions and 25 deletions.
  1. +26 −10 src/leiningen/jar.clj
  2. +2 −15 src/leiningen/uberjar.clj
View
36 src/leiningen/jar.clj
@@ -5,6 +5,7 @@
[leiningen.core.project :as project]
[leiningen.core.eval :as eval]
[leiningen.core.main :as main]
+ [bultitude.core :as b]
[clojure.string :as string]
[clojure.java.io :as io])
(:import (java.util.jar Manifest JarEntry JarOutputStream)
@@ -127,18 +128,33 @@
propagated to the compilation phase and not stripped out."
[:offline? :local-repo :certificates :warn-on-reflection])
+(defn- compile-main? [{:keys [main source-paths] :as project}]
+ (and main (some #(.exists (io/file % (b/path-for main))) source-paths)))
+
+(defn- add-main [project given-main]
+ (let [project (if given-main
+ (assoc project :main (symbol given-main))
+ project)]
+ (if (and (compile-main? project) (not= :all (:aot project)))
+ (update-in project [:aot] conj (:main project))
+ project)))
+
(defn jar
"Package up all the project's files into a jar file.
Create a $PROJECT-$VERSION.jar file containing project's source files as well
as .class files if applicable. If project.clj contains a :main key, the -main
-function in that namespace will be used as the main-class for executable jar."
- [project]
- (let [project (-> (project/unmerge-profiles project [:default])
- (project/merge-profiles [:provided])
- (merge (select-keys project whitelist-keys)))]
- (eval/prep project)
- (let [jar-file (get-jar-filename project)]
- (write-jar project jar-file (filespecs project []))
- (main/info "Created" (str jar-file))
- jar-file)))
+function in that namespace will be used as the main-class for executable jar.
+
+With an argument, the jar will be built with an alternate main."
+ ([project main]
+ (let [project (-> (project/unmerge-profiles project [:default])
+ (project/merge-profiles [:provided])
+ (merge (select-keys project whitelist-keys))
+ (add-main main))]
+ (eval/prep project)
+ (let [jar-file (get-jar-filename project)]
+ (write-jar project jar-file (filespecs project []))
+ (main/info "Created" (str jar-file))
+ jar-file)))
+ ([project] (jar project nil)))
View
17 src/leiningen/uberjar.clj
@@ -3,7 +3,6 @@
(:require [clojure.xml :as xml]
[clojure.zip :as zip]
[clojure.java.io :as io]
- [bultitude.core :as b]
[leiningen.core.classpath :as classpath]
[leiningen.core.project :as project]
[leiningen.core.main :as main]
@@ -66,17 +65,6 @@
(.flush *out*))
(.closeEntry out))))
-(defn- compile-main? [{:keys [main source-paths] :as project}]
- (and main (some #(.exists (io/file % (b/path-for main))) source-paths)))
-
-(defn- add-main [project given-main]
- (let [project (if given-main
- (assoc project :main (symbol given-main))
- project)]
- (if (compile-main? project)
- (update-in project [:aot] conj (:main project))
- project)))
-
(defn uberjar
"Package up the project files and all dependencies into a jar file.
@@ -88,10 +76,9 @@ With an argument, the uberjar will be built with an alternate main.
The namespace you choose as main should have :gen-class in its ns form
as well as defining a -main function."
([project main]
- (let [project (add-main project main)
- project (update-in project [:jar-inclusions]
+ (let [project (update-in project [:jar-inclusions]
concat (:uberjar-inclusions project))]
- (try (jar/jar project)
+ (try (jar/jar project main)
(catch Exception e
(main/abort "Uberjar aborting because jar/compilation failed:"
(.getMessage e)))))
Please sign in to comment.
Something went wrong with that request. Please try again.