Skip to content

Instantly share code, notes, and snippets.

@telent
Created September 9, 2016 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telent/7f7a4641260bb453947f0e61ea6c0d57 to your computer and use it in GitHub Desktop.
Save telent/7f7a4641260bb453947f0e61ea6c0d57 to your computer and use it in GitHub Desktop.
;; As of September 2016, using the version of boot-clj that I got by following the Nix install instructions,
;; here is how I built a clojure "hello world" as a uberjar that you can run with `java -jar`. I do
;; not claim it is the right way, merely that it worked for me. This file is build.boot
(set-env!
:resource-paths #{"src"} ; may be optional?
:source-paths #{"src"} ; my code is in src/myapp/core.clj
:dependencies '[[org.clojure/clojure "1.8.0"]]) ; not sure I'm actually using this, boot may be overriding it
(task-options!
; these are default arguments that are merged in whenever their respective tasks are called
pom {:project 'myapp ; this is java magic and i don't know why I'm doing it
:version "0.1.0"}
jar {:main 'myapp.core}
target {:dir #{"target/"}})
; these are the tasks which I want to run
(deftask build []
(comp
(aot :namespace #{'myapp.core}) ; I *think* this is needed to get a .class file for this ns into the jar
(pom)
(uber) ; unpacks all the dependencies into the output fileset
(jar) ; the file this creates is called "project.jar" no matter what the project was called
(sift :include #{#"project.jar$"}) ; remove all the other files in the output fileset
;; requirement for the following step seems to have been added quite recently as I don't see it mentioned
;; in many web examples. without it you will not get the target/ directory and will never be able to find
;; the generated example
(target) ; save the output fileset
(install) ; I thnk this also puts stuff in your local maven (may be able to skip this)
))
;; this is src/myapp/core.clj
(ns myapp.core (:gen-class)) ; gen-class is important
(defn -main []
(println "hello world"))
@telent
Copy link
Author

telent commented Sep 9, 2016

Impressions of boot as a new user:

  • I couldn't see anywhere obvious in the docs to tell me I needed to call (target)
  • I missed :gen-class but I always forget that with leiningen too, so not boot's fault
  • Having successfully avoided programming java pretty much ever since the time that applets were a thing, I have only the most superficial understanding of POMs and suchlike. I think this is required Because Reasons

To get the example to work, run

$ boot build

I have not (knowingly) used any plugins or middlewares or any other libraries here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment