Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
prep for v0.3.0; updates tools.build
Browse files Browse the repository at this point in the history
Also makes :lib optional for uber if :uber-file is passed.
  • Loading branch information
seancorfield committed Sep 16, 2021
1 parent e15ca9f commit fb11811
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

* v0.3.0 -- 2021-09-16
* `:lib` is now optional for `uber` if you pass in `:uber-file`.
* Update `tools.build` to v0.5.0 7d77952 (default basis is now "repro" without user `deps.edn`).

* v0.2.2 5a12a1a -- 2021-09-15
* Address #3 by adding an `uber` task which includes the log4j2 plugins cache conflict handler.
* Added support for many more options that `tools.build` tasks accept.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ your `:build` alias can just be:

```clojure
:build {:deps {io.github.seancorfield/build-clj
{:git/tag "v0.2.2" :git/sha "5a12a1a"}}
{:git/tag "v0.3.0" :git/sha "..."}}
:ns-default build}
```

Expand Down Expand Up @@ -40,7 +40,7 @@ _[Several functions in `clojure.tools.build.api` return `nil` instead]_
* `run-tests` -- run the project's tests.

For `deploy` and `jar`, you must provide at least `:lib` and `:version`.
For `uber`, you must provide at least `:lib` for the name of the JAR file.
For `uber`, you must provide at least `:lib` or `:uber-file` for the name of the JAR file.
Everything else has "sane" defaults, but can be overridden.

You might typically have the following tasks in your `build.clj`:
Expand Down Expand Up @@ -121,7 +121,7 @@ Or you could just make it part of your `ci` pipeline without adding that functio
The following defaults are provided:

* `:target` -- `"target"`,
* `:basis` -- `(create-basis {:project "deps.edn"}`,
* `:basis` -- `(b/create-basis {})` -- this is a reproducible basis, i.e., it ignores the user `deps.edn` file -- if you want your user `deps.edn` included, you will need to explicitly pass `:basis (b/create-basis {:user :standard})` into tasks,
* `:class-dir` -- `(str target "/classes")`,
* `:jar-file` -- `(format \"%s/%s-%s.jar\" target lib version)`,
* `:uber-file` -- `(format \"%s/%s-%s.jar\" target lib version)` if `:version` is provided, else `(format \"%s/%s-standalone.jar\" target lib)`.
Expand All @@ -138,8 +138,8 @@ the high-level defaults as follows:
* Requires: `:lib` and `:version`,
* `:target`, `:class-dir`, `:basis`, `:resource-dirs`, `:scm`, `:src-dirs`, `:tag` (defaults to `(str "v" version)`), `:jar-file`,
* `uber`
* Requires: `:lib`,
* `:target`, `:class-dir`, `:basis`, `:compile-opts`, `:main`, `:ns-compile`, `:resource-dirs`, `:scm`, `:src-dirs`, `:tag` (defaults to `(str "v" version)` if `:version` provided), `:uber-file`, `:version`
* Requires: `:lib` or `:uber-file`,
* `:target`, `:class-dir`, `:basis`, `:compile-opts`, `:main`, `:ns-compile`, `:resource-dirs`, `:scm`, `:src-dirs`, `:tag` (defaults to `(str "v" version)` if `:version` provided), `:version`
* `run-tests`
* `:aliases` -- for any additional aliases beyond `:test` which is always added,
* Also accepts any options that `run-task` accepts.
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:deps
{io.github.clojure/tools.build {:git/tag "v0.4.0" :git/sha "801a22f"}
{io.github.clojure/tools.build {:git/tag "v0.5.0" :git/sha "7d77952"}
io.github.seancorfield/build-uber-log4j2-handler {:git/tag "v0.1.0" :git/sha "ab8e499"}
io.github.slipset/deps-deploy {:sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"}}}
28 changes: 14 additions & 14 deletions src/org/corfield/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
opt :target, :class-dir, :basis, :scm, :src-dirs,
:resource-dirs, :tag, :jar-file
(see docstring for additional options)
uber -- req :lib
uber -- req :lib or :uber-file
opt :target, :class-dir, :basis, :scm, :src-dirs,
:resource-dirs, :tag, :uber-file, :version
:resource-dirs, :tag, :version
(see docstring for additional options)
run-task -- [opts aliases]
opt :java-opts -- defaults to :jvm-opts from aliases
Expand Down Expand Up @@ -74,15 +74,15 @@

(defn- default-basis
[basis]
(or basis (b/create-basis {:project "deps.edn"})))
(or basis (b/create-basis {})))

(defn- default-class-dir
[class-dir target]
(or class-dir (str (default-target target) "/classes")))

(defn- default-jar-file
[target lib version]
(format "%s/%s-%s.jar" (default-target target) (name lib) version))
(format "%s/%s-%s.jar" (default-target target) (name (or lib 'application)) version))

(defn clean
"Remove the target folder."
Expand Down Expand Up @@ -149,36 +149,36 @@
(defn uber
"Build the application uber JAR file.
Requires: :lib
Requires: :lib or :uber-file
Accepts any options that are accepted by:
* `tools.build/write-pom`
* `tools.build/compile-clj`
* `tools.build/uber`
The uber JAR filename is derived from :lib,
and :version if provided.
The uber JAR filename is derived from :lib
and :version if provided, else from :uber-file.
If :version is provided, writes pom.xml into
META-INF in the :class-dir, then
Compiles :src-dirs into :class-dir, then
copies :src-dirs and :resource-dirs into :class-dir, then
builds :uber-file into :target (directory)."
{:argslists '([{:keys [lib
{:argslists '([{:keys [lib uber-file
basis class-dir compile-opts filter-nses
ns-compile repos resource-dirs scm sort
src-dirs src-pom tag target uber-file version]}])}
[{:keys [lib] :as opts}]
(assert lib ":lib is required for uber")
(let [{:keys [class-dir ns-compile sort src-dirs src+dirs uber-file version]
src-dirs src-pom tag target version]}])}
[{:keys [lib uber-file] :as opts}]
(assert (or lib uber-file) ":lib or :uber-file is required for uber")
(let [{:keys [class-dir lib ns-compile sort src-dirs src+dirs uber-file version]
:as opts}
(jar-opts opts)]
(if version
(if (and lib version)
(do
(println "\nWriting pom.xml...")
(b/write-pom opts))
(println "\nSkipping pom.xml because :version was omitted..."))
(println "\nSkipping pom.xml because :lib and/or :version were omitted..."))
(println "Copying" (str (str/join ", " src+dirs) "..."))
(b/copy-dir {:src-dirs src+dirs
:target-dir class-dir})
Expand Down

0 comments on commit fb11811

Please sign in to comment.