Welcome! Please see the About page for a little more info on how this works.

+2 votes
in tools.deps.alpha by

There is an assumption that tools.deps will carry a :scope "provided" into the pom.xml when -Spom is run. However, not only is it not carried over, but if it already exists in the pom.xml then it is deleted...

For example:

{:deps {com.datomic/datomic-free {:mvn/version "0.9.5697" :scope "provided"}}}

becomes:

<dependency>
  <groupId>com.datomic</groupId>
  <artifactId>datomic-free</artifactId>
  <version>0.9.5697</version>
</dependency>

but should be:

<dependency>
  <groupId>com.datomic</groupId>
  <artifactId>datomic-free</artifactId>
  <version>0.9.5697</version>
  <scope>provided</scope>
</dependency>

1 Answer

+2 votes
by
selected by
 
Best answer

tools.deps does not support :scope.

by
Here's a patch that adds support

From aec6d48bf828ccdd076be248738155d97fa04477 Mon Sep 17 00:00:00 2001
From: Thomas Spellman <thos37@gmail.com>
Date: Sat, 22 Feb 2020 22:09:49 -0800
Subject: [PATCH] support :scope in deps map when generating pom.xml

---
 src/main/clojure/clojure/tools/deps/alpha/gen/pom.clj | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/main/clojure/clojure/tools/deps/alpha/gen/pom.clj b/src/main/clojure/clojure/tools/deps/alpha/gen/pom.clj
index 303ae93..1f24d31 100644
--- a/src/main/clojure/clojure/tools/deps/alpha/gen/pom.clj
+++ b/src/main/clojure/clojure/tools/deps/alpha/gen/pom.clj
@@ -21,7 +21,7 @@
 (xml/alias-uri 'pom "http://maven.apache.org/POM/4.0.0")
 
 (defn- to-dep
-  [[lib {:keys [mvn/version classifier exclusions] :as coord}]]
+  [[lib {:keys [mvn/version classifier exclusions scope] :as coord}]]
   (if version
     (cond->
       [::pom/dependency
@@ -38,7 +38,10 @@
                     [::pom/exclusion
                      [::pom/groupId (namespace excl)]
                      [::pom/artifactId (name excl)]])
-               exclusions)]))
+               exclusions)])
+
+      scope
+      (conj [::pom/scope scope]))
     (printerrln "Skipping coordinate:" coord)))
 
 (defn- gen-deps
--
2.21.0 (Apple Git-122.2)
by
Thanks for the patch but we intentionally don’t support it and don’t want to add it. The clj approach is to use aliases to allow the construction of classpath variants. If you want this in your pom, you will need to maintain your own pom.
by
Ah, I see now.  That makes sense.  Thanks!
by
@alexmiller Thanks for the clarification about this. Generally speaking, this is all fine and dandy, but I'm having trouble getting cljdoc to work with this, because it needs dependencies which might otherwise be included in aliases to be in the pom and marked `<scope>provided</scope>`.

An alternative to supporting `:scope "provided"` would be for `tools.deps` to do an upsert on the `<dependencies>` list. Is that something you'd consider? The only alternative available seems to be for me write a little script that manually munges in the `<scope>provided</scope>` dependency, which feels pretty hacky.

Thanks as always for your time!
by
@alexmiller Thanks for the clarification about this. Generally speaking, this is all fine and dandy, but I'm having trouble getting cljdoc to work with this, because it needs dependencies which might otherwise be included in aliases to be in the pom and marked `<scope>provided</scope>`.

An alternative to supporting `:scope "provided"` would be for `tools.deps` to do an upsert on the `<dependencies>` list. Is that something you'd consider? The only alternative available seems to be for me write a little script that manually munges in the `<scope>provided</scope>` dependency, which feels pretty hacky.

See https://github.com/cljdoc/cljdoc/issues/404#issuecomment-730549210

Thanks as always for your time!
by
We are working towards a more configurable way to utilize pom gen in the future and that may be room at that point to have more influence on this process.
...