tools-build 2024-02-21

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

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

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

: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...

yeah, we want it for that too 🙂

this is a library

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).

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

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... 🤔

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.

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

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.

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

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...

yeah I should play around w/ that approach some more