seancorfield / depstar

Builds JARs, uberjars, does AOT, manifest generation, etc for deps.edn projects
https://cljdoc.org/d/com.github.seancorfield/depstar/CURRENT
239 stars 19 forks source link

`:extra-paths` not used unless I specify `:aliases` #99

Closed opqdonut closed 3 years ago

opqdonut commented 3 years ago

Hi,

Thanks for the tool! I'm probably missing something obvious here, but I have a problem with :extra-paths specified for my depstar alias not working unless I refer to the alias itself using :aliases. Here's an example that works for me:

{:aliases {:uberjar {:extra-deps {com.github.seancorfield/depstar {:mvn/version "2.1.278"}}
                     :extra-paths ["build-target"]
                     :exec-fn hf.depstar/uberjar
                     :exec-args {:main-class "foo.main"
                                 :aliases [:uberjar]
                                 :compile-ns [foo.main quux bar]
                                 :jar "target/foo.jar"}}

However, before I added the :aliases the :extra-paths wasn't getting obeyed. I'm not sure how this is possible, since I imagined that clj will process the :extra-paths before calling the :exec-fn.

If this can be fixed on the depstar side, that would be nice, if not, a caveat in the docs would be nice.

seancorfield commented 3 years ago

depstar is supposed to run as a "tool" -- via :replace-deps, not :extra-deps. It then computes a "basis" -- a classpath -- so it knows what goes into the JAR file. This is explained in the documentation.

In particular, if you need anything added to the JAR that is not part of your basic :deps or :paths, you need to tell depstar about the aliases that would add those deps and paths to the classpath. See the example in the docs about web assets.

Here's what you should have in your deps.edn file per the README, augmented for your project:

{
 :aliases {
  ;; build an uberjar (application) with AOT compilation by default:
  :uberjar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.278"}}
            :exec-fn hf.depstar/uberjar
            :exec-args {:aot true ; unless you specifically do NOT want everything AOT'd
                        :main-class foo.main ; a symbol is fine here
                        :aliases [:build-target] ; specify the alias(es) to use for the classpath
                        :jar "target/foo.jar"}}
  :build-target {:extra-paths ["build-target"]} ; specify additional classpath stuff
 }
}

In particular, you do not want to use :aliases [:uberjar] because that will cause all of depstar and all of its dependencies to also be added to your uberjar.

opqdonut commented 3 years ago

Thanks for the thorough answer! I had tried :replace-deps earlier but ran into some errors, but I got those sorted out now.