This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-09
Channels
- # announcements (26)
- # babashka (4)
- # beginners (17)
- # calva (21)
- # cider (13)
- # clerk (17)
- # clj-commons (23)
- # clj-kondo (3)
- # cljdoc (47)
- # cljsrn (10)
- # clojure (123)
- # clojure-belgium (2)
- # clojure-dev (25)
- # clojure-europe (34)
- # clojure-gamedev (2)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-norway (4)
- # clojure-uk (4)
- # clojurescript (86)
- # cursive (12)
- # datahike (2)
- # datomic (2)
- # emacs (4)
- # fulcro (6)
- # funcool (15)
- # instaparse (1)
- # integrant (11)
- # jobs (1)
- # joyride (9)
- # kaocha (3)
- # membrane (8)
- # off-topic (1)
- # pathom (4)
- # practicalli (2)
- # quil (1)
- # rdf (1)
- # reagent (9)
- # remote-jobs (1)
- # shadow-cljs (27)
- # spacemacs (4)
- # specter (1)
- # sql (11)
- # tools-deps (55)
- # vim (1)
does anyone know how I can add a “provided” dependency to my generated pom.xml, using b/write-pom? I’m reading code here:
https://github.com/clojure/tools.build/blob/master/src/main/clojure/clojure/tools/build/tasks/write_pom.clj#L222
and it looks like there is no way to add my own pom entries… dependencies
is overwritten by the basis
I'm curious about the use case -- provided
has always seemed a bit odd to me: either the dependency is needed or it isn't... :thinking_face:
provided is usually used for local testing or optional deps but in deps.edn you can do this with aliases
@U04V70XH6 cljdoc needs these to do analysis if you have a dependency that you want the user to specify
you are correct that there is no way to add custom deps to the generated pom.xml
so if I want to force the user to manually declare an SCI dependency, for example
if you want to make a feature request --> https://ask.clojure.org
@U064X3EF3 I’m going to add it to the basis, and then do
(xml/alias-uri 'pom "")
(alter-var-root
#'write-pom/to-dep
(fn [old]
(fn [[_ {:keys [mvn/scope]} :as pair]]
(cond-> (old pair)
scope
(conj [::pom/scope scope])))))
@U04V70XH6 for example if @U04V15CAJ wanted cljdoc to work with https://github.com/babashka/sci.configs (which I know he doesn’t!), he’d need to add provided deps
That's a "bug" with cljdoc as far as I'm concerned -- and they know about it but haven't come up with a good way to address it yet.
but doesn't tools build merge with an existing pom.xml
? I remember there was something like this...? So you could add some stuff in there which should always left in or does it override dependencies?
I think there was already a request for this on ask, I'll see if I can find it
(and I've run into it with some of my libraries on cljdoc)
@U04V15CAJ yeah, but it only merges one level deep
dependencies from the basis wipe out the dependencies entry in the pom.xml template
@U04V70XH6 I personally like provided dependencies… “I won’t work without this but you need to be explicit about what you want”
@U017QJZ9M7W clojure.data.xml + add some deps yourself in tools.build? It's not that hard :) it comes with bb too
yup, doing that now!
it completely replaces some sections -depedencies, repositories, etc
(def basis
(-> (b/create-basis
{:project "deps.edn"
:extra
{:deps
{'org.babashka/sci
{:mvn/version "0.6.37"
:mvn/scope "provided"}}}})))
that works, given
(ns build
"tools.build declarations for the mafs.cljs library."
(:require [clojure.data.xml :as xml]
[clojure.tools.build.api :as b]
[clojure.tools.build.tasks.write-pom :as write-pom]))
(xml/alias-uri 'pom "")
(alter-var-root
#'write-pom/to-dep
(fn [old]
(fn [[_ {:keys [mvn/scope]} :as pair]]
(cond-> (old pair)
scope
(conj [::pom/scope scope])))))
@U04V70XH6 use case is for libraries with namespaces that integrate with third party libraries that are optional?
@U017QJZ9M7W What I meant was rewriting the pom after tools build had written it, not actually monkey-patch tools build but since this is in your private build, I guess do what you want :)
@U09LZR36F Right, but you don't need those in the POM -- you can use aliases to develop with.
Ah, but cljdoc was maven oriented. And any other maven oriented tools need that annotation.
Right, but cljdoc is also looking at generating docs from source only (git dep) projects so I'd say its current Maven dependence is historical 🙂
I’ll do it the right way eventually, you’re of course right @U04V15CAJ …
Cljdoc will also eventually support static analysis to glean the public API. Which should help with many awkwardnesses and failed API analyses. I think this will be the default, and for libs that generate their API at load time - they will still be able to opt for dynamic analysis.
(A foretaste of docs using static analysis: https://github.com/borkdude/quickdoc)
> Maven dependence is historical But will likely persist @U04V70XH6, I think, anyway.
@UE21H2HHD Well, if cljdoc is able to process git deps, those won't require pom.xml
and so cljdoc would be able to analyze libraries without the "Maven dependence" which was what I was leaning into there... 🙂
Maybe what @U09LZR36F meant is that your analyzed dependency is a mvn artifact and that you can't update your docs unless you push a new version? I don't know if that's still the case, but this was coupled to a mvn version
Gotcha @U04V70XH6, makes sense, somebody with a lib that has optional deps would be more likely to take the analyze from git repo sources route (when that becomes available).
@U04V15CAJ, if that was what @U09LZR36F was getting at https://github.com/cljdoc/cljdoc/blob/master/doc/userguide/for-library-authors.adoc#articles-override.
The trade off between building calling a function through the java command line against a jar, and calling cli -X and passing it a clojure function, is just that the later will be slower right?
As in, for functions where the execution time isn't a factor, it's fine to use either route.
Yeah.
can you not do clj -Sdeps '{:deps {my/lib {:local/root "jar.jar"}}}' -X some/fn
regardless if source is present or not?
what the later does is more context dependent than the former, and what it does will determine if it is slower than the former or not
Is there a way to have two -main
functions?
Asking the question another way, If the .clj files on my deps :path already contain a -main function with a the command to generate classes (:genc-class)
, can I add another -main function, and specify that one in a separate build (build.clj) so I can end up with two jars each that call different main functions?
Maybe using the build api function https://clojure.github.io/tools.build/clojure.tools.build.api.html#var-set-project-root.21! ? which takes, at a glance, a :main option for main class symbol?
Does this question indicate i have strayed from the path and should trying something else?
You can have -main
in every single namespace but you can only have one default -main
that is invoked via java -jar
without specifying the class to invoke.
java -jar ... clojure.main -m some.name
will invoke
(we have several JAR files that contain multiple -main
functions and we choose which one to invoke via clojure.main
)
that makes sense, for some reason i hadn't considered that you could pass the namespace to the java cli.
is that what it's called? the java cli?
I suspect people just call it "the java
command" but I hadn't really thought about it...
java -jar ... MyPackage.MyClass
has been supported for all of Java's life I think -- and clojure.main
is "just" a class in the Clojure runtime.
(and you can probably just do java -jar ... some.name
if you have (:gen-class)
in that ns -- I'm just used to bouncing via clojure.main
for a ns that might not be AOT compiled)
Oh, not java -jar ... MyPackage.MyClass
-- java -cp ... MyPackage.MyClass
sorry.
Here we go:
(~/clojure/mains)-(!2016)-> cat src/multi/another.clj
(ns multi.another
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "I'm another main!"))
Thu Feb 09 11:18:09
(~/clojure/mains)-(!2017)-> cat src/multi/mains.clj
(ns multi.mains
(:gen-class))
(defn greet
"Callable entry point to the application."
[data]
(println (str "Hello, " (or (:name data) "World") "!")))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(greet {:name (first args)}))
Thu Feb 09 11:18:12
(~/clojure/mains)-(!2018)-> java -jar target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar
Hello, World!
Thu Feb 09 11:18:22
(~/clojure/mains)-(!2019)-> java -jar target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar argument
Hello, argument!
Thu Feb 09 11:18:28
(~/clojure/mains)-(!2020)-> java -cp target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar multi.mains
Hello, World!
Thu Feb 09 11:18:48
(~/clojure/mains)-(!2021)-> java -cp target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar multi.mains argument
Hello, argument!
Thu Feb 09 11:18:52
(~/clojure/mains)-(!2022)-> java -cp target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar multi.another
I'm another main!
Thu Feb 09 11:19:02
(~/clojure/mains)-(!2023)->
https://github.com/hiredman/clojure-site/blob/patch-4/content/guides/running_a_clojure_program.adoc might have some useful context
Ah thanks @U04V70XH6 and @U0NCTKEV8 the -cp
variant had not occurred to me!