@cap10morgan Some feedback on the PR: I think it's worth figuring out why resources will be in the uberjar by default, other than "it seems to work". Also I think it's better to use a temporary directory to copy bb.edn into than the resources directory, as there might already be such a directory and you would be overwriting the contents.
babashka has its own old version of depstar built in for making uberjars, perhaps we could tweak that to include certain files as well
https://github.com/babashka/depstar/tree/c419b8c82041855d55593c5b561fc7cea8234712
or we could move to the new tools.build uberjar code instead. it's fully compatible with bb except for the basis stuff, which we don't really need
the uberjar code is pretty thin
but let's move in the smallest step possible and just do with what we have right now
looks like in depstar it's just b/c its on the classpath: https://github.com/seancorfield/depstar/issues/27
so we could just put a temp dir on the classpath while we're building the uberjar
instead
@cap10morgan yes, but resources isn't always on bb's classpath, only if you add that
I tried out the tools.build api a little but got confused by the basis stuff and how it would relate here
so I don't understand how it ends up working
probably just on the classpath where I tried it (e.g. in the :paths vector in my deps.edn files)
so I'll just do it the way you suggest instead
you only need a classpath in the end. if you have that, you don't need the basis stuff which depends on mvn etc
bb should not look at deps.edn, unless you tell it to
seemed like the uber task in tools.build wanted a basis, but maybe it isn't required or it doesn't need much of it
yes, the uber task wants a basis but once you replace that with a classpath, the rest of the code works.
ah ok
cool
I can try converting it to that if you want
let's save that for another time
separate issue
@borkdude for the temp dir that we copy the bb.edn into and add to the classpath while building the uberjar, you think it matters if it's inside the project root (vs. just the system's temp dir)?
it gets deleted once the jar is built
pushed the system temp dir version just now, but happy to change if you want
@cap10morgan I haven't tried, but won't deps from bb.edn be fetched again when you execute the uberjar, while they are already within the uberjar, when you start that uberjar? We could also write something in the uberjar's manifest about the config.
not sure, I haven't tried that either
Well I don't see any special handling not to do this, it seems the bb.edn is picked up as if you're not inside an uberjar
which should not happen
not sure I follow
like a bb.edn in the same dir as the .jar file?
yes?
yeah I saw that too
I can make it not do that
Also tasks etc do not really apply
or do they...?
bb uberjar.jar run task1...hmm
maybe not
I think we should be conservative and only copy the pods config into some uniquely named file and write something in the manifest file that pods should be loaded from there
I think the latest code in the PR already skips using a bb.edn in the same dir as the .jar file. Because of the cond. It will hit the jar branch and either find a file in the jar or not, but if it doesn't it should just return nil, not skip down to the :else where the ./bb.edn loading happens.
yeah that's good but the uberjar invocation will still trigger dependency downloading which should not happen anymore
also tasks should probably be elided from the uberjar
that's why I think eliding most of the bb.edn in the uberjar would be better
e.g. (select-keys bb.edn [:pods])
seems reasonable
until we have a reason to support more of it
in the future we could support bundling the pods with the uberjar too but this is out of scope for now ;)
hmm... it's not putting deps into the uberjar
oh, perhaps b/c if its only declared in bb.edn's :deps, I need to manually add it to my uberjar classpath? b/c clojure -Spath will only give me the deps.edn ones, huh?
I don't follow, why are you talking about clojure -Spath?
from the babashka book: bb -cp $(*clojure* -A:remove-clojure -Spath) uberjar foo.jar -m foo
that's how I'm getting my classpath for the uberjar I'm testing with
that's an example from before bb.edn
ah
we should update this
ok, yeah, eliding that worked (even better)
:pods only is pushed
a minor thing but:
->> bb-edn-pods (hash-map :pods)
can be written as {:pods bb-edn-pods}, I find that a little easier to readYep, no problem
pushed
ok, now we should also have tests for this. One thing to note is that local sources are always resolved relative to the bb.edn file, unless you set --deps-root but I don't know how that plays out if you invoke the uberjar from another directory now, e.g.
/tmp/foo $ bb /tmp/bar/uberjar.jar I suspect that will error out unless we set --deps-root (or unset it)
but maybe not, I'm just not sure :)
my simple tester jar works from a different dir
w/ a dep
ok, that's assuring
writing up a test now
Maybe this part of the code isn't hit anymore: https://github.com/babashka/babashka/blob/72ae6638422c542055dda8fc068f995cbfd9f61f/src/babashka/impl/deps.clj#L63 in the uberjar, since we cut out the deps part, so that makes sense.
ok just pushed a test. let me know if there are other aspects you'd like tested
cool, I'll take a look tomorrow again, thanks!