tools-build

seancorfield 2026-05-21T19:40:44.887429Z

I just noticed that write-pom supports :optional in deps, to produce true in pom.xml... I don't remember any discussions about that and, I'll be honest, I don't really understand what it's for (after reading various Maven docs)... I hoped that a deps.edn project that depends on a JAR with an optional dep in pom.xml would not bring in that transitive dep -- which seemed to be what the Maven docs indicated -- but that's not the case. [edit: this actually does seem to work on a second test so I'm not sure why I wasn't seeing this before] However, provided is something that has been asked for and discussed and I believe that would omit the transitive dep (yes?). Is there still some blocker to something like :scope :provided in a dependency being handled by write-pom?

Alex Miller (Clojure team) 2026-05-21T19:58:02.833029Z

write-pom and deps.edn deps are two different contexts of course, and those contexts have different intents. write-pom is about literally writing a Maven pom, producing a Maven specified artifact. I don't remember what drove supporting :optional there but in general, I'm fine with providing features to let you make the pom you want to make. If you want more things that don't exist there, feel free to ask for them. The goal of the deps.edn has nothing to do with Maven or its features. The domain is similar and we support many features that overlap, but the goal is not Maven in Clojure syntax. In general, deps chooses to specify the classpath in :deps, and then allow you to add modifiers to specify alternate classpaths. I'm in support of solving a user problem. but I don't think "support :provided" is the problem, so I'd rather state what that is and see if people have that need, and then decide how to solve it. I don't really care whether it maps to Maven :provided scope or not in this context.

Alex Miller (Clojure team) 2026-05-21T19:58:56.569419Z

I don't recall an issue for this already, maybe there is one. it's not something people ask me about often.

seancorfield 2026-05-21T20:12:02.398289Z

I think it mostly crops up in the context of http://cljdoc.org which needs "extra" deps for some projects that are not part of the regular deps for a project. <scope>provided</scope> works for http://cljdoc.org and it seems like when deps.edn specifies a Maven dep (Clojars) that has that, it "does the right thing", i.e., doesn't bring in the provided dep. So the problem is that there's currently no way to tell write-pom to add that. I happened to notice :optional true support in the source when wondering what would be involved and hoped -- based on the Maven docs -- that it would do something similar to <scope>provided</scope> but, alas, it does not. My workaround for now is to have the "provided" dep under a :provided alias -- with :optional true, so I can use it when testing etc and then call write-pom with a :basis that is built with that alias... and then slurp/replace/spit the pom.xml file between write-pom and jar calls, changing <optional>true</optional> to <scope>provided</scope> -- this seems to work just fine, but of course it's abusing :optional true support 🙂

Alex Miller (Clojure team) 2026-05-21T20:20:31.985119Z

that seems fine and not abusing it. optional and provided are practically the same in Maven. except provided is a scope and optional is a flag

Alex Miller (Clojure team) 2026-05-21T20:21:17.601919Z

in both cases they are marking a dependency that is not required (but for different reasons - either the runtime environment provides or it is not always needed)

seancorfield 2026-05-21T20:22:18.531639Z

Well, I tried <optional>true</optional> and depending on the JAR still brought in that optional dep -- which surprised me. When I switched it to <scope>provided</scope> then it worked. So, it seems (based on my admittedly limited testing) that an optional Maven dep is not treated the same as scope provided by tools.deps?

seancorfield 2026-05-21T20:22:52.342209Z

(hence, part of my original question was "what does <optional> really do?" 🙂 )

Alex Miller (Clojure team) 2026-05-21T20:23:13.769509Z

> depending on the JAR still brought in that optional dep what is the actor here? maven?

seancorfield 2026-05-21T20:23:32.817429Z

In deps.edn, I had a :local/root dep on the JAR file.

seancorfield 2026-05-21T20:23:48.126269Z

(and now I've tested it with a :mvn/version dep too)

Alex Miller (Clojure team) 2026-05-21T20:24:06.449109Z

so you're saying tools.deps including a Maven artifact with an optional dep is including that transitive dep?

Alex Miller (Clojure team) 2026-05-21T20:24:47.705539Z

that is not the intent, if you're seeing that

seancorfield 2026-05-21T20:24:50.406969Z

In both cases, <scope>provided</scope> works (i.e., the dep is not brought in), but an <optional>true</optional> dep doesn't (i.e., the dep is still brought in).

seancorfield 2026-05-21T20:25:17.886069Z

It was limited testing, but I was surprised to see the optional dep show up on the classpath, yes.

seancorfield 2026-05-21T20:27:50.789839Z

Hmm, looks like that should work...

seancorfield 2026-05-21T20:29:07.503239Z

I'll have a play around but maybe something is dropping the optional key somewhere... It would certainly be convenient if that actually does work 🙂 I'll get back to you on that...

seancorfield 2026-05-21T20:34:15.049859Z

I created a couple of new projects to test this and... :optional true does work there... I'll do some more digging on why it didn't work for what I was trying before...

seancorfield 2026-05-21T21:31:43.930549Z

Looks like this is a solution for http://cljdoc.org too -- :optional true in an :extra-deps dep under an alias. https://github.com/seancorfield/rephrase/blob/main/deps.edn#L4-L6 https://github.com/seancorfield/rephrase/blob/main/build.clj#L34 Doesn't show up when used via deps.edn:

> clojure -Spath -Sforce -Sdeps '{:deps {org.corfield/rephrase {:mvn/version "1.0.2"}}}'
src:/home/sean/.m2/repository/org/clojure/clojure/1.12.5/clojure-1.12.5.jar:/home/sean/.m2/repository/org/corfield/rephrase/1.0.2/rephrase-1.0.2.jar:/home/sean/.m2/repository/org/clojure/core.specs.alpha/0.4.74/core.specs.alpha-0.4.74.jar:/home/sean/.m2/repository/org/clojure/spec.alpha/0.5.238/spec.alpha-0.5.238.jar

Alex Miller (Clojure team) 2026-05-21T21:45:43.335129Z

the line I pointed to is really for pulling deps from a maven artifact, not an extension to dep maven coordinate spec

seancorfield 2026-05-21T21:46:28.179189Z

Yes, agreed.

Alex Miller (Clojure team) 2026-05-21T21:46:36.051829Z

that is, :optional is not a valid key for maven deps like you're using it

seancorfield 2026-05-21T21:47:03.231279Z

But write-pom explicitly supports it.

seancorfield 2026-05-21T21:48:23.265699Z

It's supported in the coord just like exclusions is.

Alex Miller (Clojure team) 2026-05-21T21:48:53.151179Z

that's not a documented feature of write-pom

seancorfield 2026-05-21T21:49:08.740799Z

Maybe it should be? 🙂

Alex Miller (Clojure team) 2026-05-21T21:50:53.839059Z

hrm

seancorfield 2026-05-21T21:52:46.111179Z

Looks like that code is at least six years old now?

Alex Miller (Clojure team) 2026-05-21T21:53:09.726519Z

I'm sure it's older than that. I'm not going to take it away or anything.

👍🏻 1
seancorfield 2026-05-21T22:05:23.474479Z

If it was documented, you could probably close out requests for :scope :provided where those are intended to solve the cljdoc issue...

seancorfield 2026-05-21T22:06:17.438409Z

At this point, I think :optional is a good solution to that (despite being undocumented), and it leaves the whole <scope> thing for consideration independently.