tools-build

liebs 2023-05-09T15:53:16.694399Z

tools.build does not natively support WARs, is that right? If I want to deploy a Clojure web app that does not embed a server, is there a way to package a JAR to do this? I've been looking at Jetty documentation and it seems like I need a ServletContext in which I expose my Ring handlers (which are servlets if I am not mistaken). Provided I have this (and anything else I may need), is there a way to get this job done? Possibly through some combination of tools.build and Maven directly?

kardan 2023-05-16T09:56:11.456779Z

I never came around to build anything, Turned out I did not really need to for the task I had at hand 🤷

Alex Miller (Clojure team) 2023-05-09T16:00:01.999329Z

correct, there are no provided tasks for wars. I'm in no way opposed to that, just wasn't something I wanted to take on at the time. Would be open to additions or seeing external libs to do so. it's possible you could get somewhere with a combination of pom gen and shelling out to a mvn process

liebs 2023-05-09T16:05:53.205629Z

cool, I'll see what I can figure out. The salient difference seems to be between the WEB-INF and META-INF directories that get outputted, though I imagine that that is not as simple as a name change. Guess I'll find out 🤷🏻‍♂️ thanks!

Alex Miller (Clojure team) 2023-05-09T16:38:38.218239Z

there is an ask question for this and a corresponding jira btw https://ask.clojure.org/index.php/11341/possible-build-uberwar-using-deps-using-tools-build-other-tool?show=11343#a11343 - happy to have votes or info on those

👀 1
Alex Miller (Clojure team) 2023-05-09T16:46:52.617739Z

mechanically, war files are just jar files with stuff in special places, and tools.build supports both copying stuff into an assembly directory and jar'ing from there, so you have much of the tools you need. assembling the jar files is probably the least obvious part of that, but the basis contains a :libs map that includes the path to jar files, so it is not a big leap to iterate over that map and copy the jar files to a place.

Apple 2023-05-09T22:18:02.103619Z

I have this code in user.clj. (def xyz (fn-might-throw-error)) I b/compile it and the fn throws an error and the compile fails. Does it mean the compile process actually runs the code during compilation and why?

seancorfield 2023-05-09T22:24:59.913039Z

If user.clj is on the classpath, Clojure automatically loads (and compiles and runs) it.

seancorfield 2023-05-09T22:26:03.339999Z

You should not have user.clj on your regular classpath -- you should put it in something like a dev/ folder and have a :dev alias with :extra-paths ["dev"] so it is only added when you are doing development.

Apple 2023-05-09T22:26:12.001719Z

i pick the wrong name here.

seancorfield 2023-05-09T22:26:29.442639Z

(I personally think the auto-loading of user.clj was a bad idea but it got added to Clojure a very long time ago)

Apple 2023-05-09T22:26:35.887449Z

it's a source file deep under src/

seancorfield 2023-05-09T22:27:01.823009Z

Oh, OK. So not literally (ns user ..)

Apple 2023-05-09T22:27:14.941839Z

Right...

seancorfield 2023-05-09T22:27:17.181019Z

Well, top-level def forms are evaluated whenever a ns is loaded.

seancorfield 2023-05-09T22:27:24.206069Z

And compilation loads nses.

seancorfield 2023-05-09T22:27:54.881409Z

A top-level def form should never cause side-effects (e.g,. throw exceptions).

seancorfield 2023-05-09T22:28:27.512699Z

A quick workaround would be to do (def xyz (delay (fn-might-throw-error))) and then @xyz instead of plain xyz wherever you use it.

seancorfield 2023-05-09T22:28:49.837449Z

But it would be better to just not have top-level def forms that aren't simple constant expressions.

Apple 2023-05-09T22:29:42.532909Z

ok that makes senses. thanks.