tools-build

cap10morgan 2024-02-21T18:34:48.544279Z

I have some Java code that needs to be compiled in a project and have setup a build task and a :deps/prep-lib entry for it, but I'm wondering if there's a way to automate compiling it on REPL startup? I've gotten as far as pulling in the build ns in my dev/user.clj and calling the compile fn in there, but then I still can't load it from that REPL. It seems like it's caching the fact that the .class files didn't exist when the REPL was started?

Alex Miller (Clojure team) 2024-02-21T18:45:07.827489Z

yeah, I think Java classloaders don't like that

Alex Miller (Clojure team) 2024-02-21T18:46:06.217239Z

this kind of thing is what people use https://github.com/ztellman/virgil for in case that's helpful

cap10morgan 2024-02-21T18:47:09.117289Z

OK, I had run across that but wasn't sure if it was needed here. I'll take a look at it.

cap10morgan 2024-02-21T18:48:08.374879Z

Hmm... looks like it doesn't directly support tools.deps / .build

Alex Miller (Clojure team) 2024-02-21T18:49:03.109589Z

it pre-dates those but I suspect the distance to make it work is probably small

seancorfield 2024-02-21T18:50:16.601779Z

:deps/prep-lib is for libraries that need a build step before other users can consume them -- I've seen a couple of people recently trying to use it for a sort of precompile step in their current (application) project...

cap10morgan 2024-02-21T18:50:36.145339Z

yeah, we want it for that too 🙂

cap10morgan 2024-02-21T18:50:46.874959Z

this is a library

seancorfield 2024-02-21T18:51:25.831249Z

What I've done in older projects is used :main-opts with -e and the compile call and then -r to start a bare REPL or -e to invoke some REPL startup code (e.g., for nREPL etc).

seancorfield 2024-02-21T18:52:19.428459Z

See https://github.com/seancorfield/cfml-interop/blob/develop/deps.edn for example.

👍 1
cap10morgan 2024-02-21T18:54:13.322859Z

I wonder if the :deps/prep-lib would be invoked if I consumed this as a lib w/ :local/root "." in my :dev alias...

cap10morgan 2024-02-21T18:58:35.428379Z

Guess I would have to run clj -X:deps prep from the REPL and then likely be right back where I am now w/ the classloaders not seeing the classes that didn't exist when they were started... 🤔

seancorfield 2024-02-21T19:01:31.013469Z

Well, prep is a "one-shot" thing to make a library consumable. It's not intended for repeated use -- since the :ensure folder will exist once you've compiled the code once. prep will only do something if that folder doesn't exist.

seancorfield 2024-02-21T19:01:47.680399Z

(at least, that's how I understand it)

cap10morgan 2024-02-21T19:02:22.554489Z

yeah. that would be 90% better than what we have now. the java not being compiled at all at repl startup is the main thing we're trying to automate.

cap10morgan 2024-02-21T19:03:07.279579Z

guess we may have to just do it in editor-specific ways

seancorfield 2024-02-21T19:20:47.718089Z

If you have a standardized way to start a REPL across the team, you could put that behind an alias along with the -e to compile stuff...

cap10morgan 2024-02-21T19:21:31.645199Z

yeah I should play around w/ that approach some more