Skip to content

Commit

Permalink
Merge pull request #15 from parenthesin/refact/using-tools-build
Browse files Browse the repository at this point in the history
refact: using tools.build to pack uberjar
  • Loading branch information
rafaeldelboni authored Apr 23, 2023
2 parents 0ef07fa + 6144740 commit b11d0d4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Setup clojure-lsp
uses: clojure-lsp/setup-clojure-lsp@v1
with:
clojure-lsp-version: 2022.09.01-15.27.31
clojure-lsp-version: 2023.04.19-12.43.29

- name: Execute lint checks
run: |
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ You can start a repl open and evaluate the file `src/microservice_boilerplate/se
### Uberjar
You can generate an uberjar and execute it via java in the terminal:
```bash
# genarate a service.jar in the root of this repository.
clj -X:uberjar
# genarate a target/service.jar
clj -T:build uberjar
# execute it via java
java -jar target/service.jar
```
Expand All @@ -119,8 +119,8 @@ java -jar target/service.jar
- [aero](https://github.com/juxt/aero) Configuration file and enviroment variables manager
- [timbre](https://github.com/ptaoussanis/timbre) Logging library
- [next-jdbc](https://github.com/seancorfield/next-jdbc) JDBC-based layer to access databases
- [honeysql](https://github.com/seancorfield/honeysql) SQL as Clojure data structures
- [depstar](https://github.com/seancorfield/depstar) Generates Uberjars for releases
- [hikaricp](https://github.com/brettwooldridge/HikariCP) A solid, high-performance, JDBC connection pool at last
- [tools.build](https://github.com/clojure/tools.build) Clojure builds as Clojure programs

### Tests & Checks
- [kaocha](https://github.com/lambdaisland/kaocha) Test runner
Expand Down
35 changes: 35 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(ns build
(:refer-clojure :exclude [test])
(:require [clojure.tools.build.api :as b]))

(def default-lib 'com.github.parenthesin/microservice-boilerplate-malli)
(def default-main 'microservice-boilerplate.server)
(def default-version "0.0.1-SNAPSHOT")
(def class-dir "target/classes")

(defn- uber-opts [{:keys [lib main uber-file version] :as opts}]
(let [actual-lib (or lib default-lib)
actual-main (or main default-main)
actual-version (or version default-version)
actual-uber-file (or uber-file (format "target/%s-%s.jar"
actual-lib
actual-version))]
(assoc opts
:lib actual-lib
:main actual-main
:uber-file actual-uber-file
:basis (b/create-basis {})
:class-dir class-dir
:src-dirs ["src"]
:ns-compile [actual-main])))

(defn uberjar "Build the Uberjar." [opts]
(b/delete {:path "target"})
(let [{:keys [main uber-file] :as opts} (uber-opts opts)]
(println "\nCopying source" class-dir)
(b/copy-dir {:src-dirs ["resources" "src"] :target-dir class-dir})
(println (str "\nCompiling " main))
(b/compile-clj opts)
(println "\nBuilding JAR on" uber-file)
(b/uber opts))
opts)
23 changes: 10 additions & 13 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
com.github.parenthesin/components {:mvn/version "0.0.2"
com.github.parenthesin/components {:mvn/version "0.1.2"
:exclusions [prismatic/schema]}
com.github.seancorfield/honeysql {:mvn/version "2.4.1011"}
metosin/malli {:mvn/version "0.10.4"}
com.github.seancorfield/honeysql {:mvn/version "2.4.1026"}
metosin/malli {:mvn/version "0.11.0"}
metosin/reitit-swagger {:mvn/version "0.6.0"}
org.postgresql/postgresql {:mvn/version "42.6.0"}}
:aliases
Expand All @@ -16,17 +16,14 @@
nubank/state-flow {:mvn/version "5.14.4"}}
:main-opts ["-m" "kaocha.runner"]}

:clojure-lsp {:replace-deps {com.github.clojure-lsp/clojure-lsp-standalone {:mvn/version "2023.02.27-13.12.12"}}
:clojure-lsp {:replace-deps {com.github.clojure-lsp/clojure-lsp-standalone {:mvn/version "2023.04.19-12.43.29"}}
:main-opts ["-m" "clojure-lsp.main"]}

:migratus {:main-opts ["-m" "parenthesin.migrations"]}
:nrepl {:extra-deps {cider/cider-nrepl {:mvn/version "0.30.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

:uberjar {:deps {io.github.seancorfield/build-clj
{:git/tag "v0.9.2" :git/sha "9c9f078"
:deps/root "slim"}}
:exec-fn org.corfield.build/uber
:exec-args {:main microservice-boilerplate.server
:uber-file "target/service.jar"}}
:migratus {:main-opts ["-m" "parenthesin.helpers.migrations"]}

:nrepl {:extra-deps {cider/cider-nrepl {:mvn/version "0.30.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}}}
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.9.4"}}
:ns-default build
:exec-args {:uber-file "target/service.jar"}}}}

0 comments on commit b11d0d4

Please sign in to comment.