Fork me on GitHub
#tools-deps
<
2021-08-11
>
Jacob Emcken20:08:37

I'm was looking for a way to do lein install but with cli tools. I found clojure -X:deps mvn-install but that requires me to reference a jar file. So I guess my question is... how to I build the jar file then? 😅

Alex Miller (Clojure team)20:08:32

tools.build of course :)

Jacob Emcken20:08:13

I cloned the Clojure library https://github.com/nextjournal/beholder tbh I don't understand how I am supposed to build it

seancorfield20:08:18

You generally don't need to install libraries locally to use them. Just declare them as dependencies in your project.

Jacob Emcken20:08:43

I know that but I changed something in it that I want to try out

seancorfield20:08:01

OK, so use :local/root as a dependency on it.

Jacob Emcken20:08:23

in a lein project 😉

seancorfield20:08:36

Haha... OK, well, there's your problem 🙂

seancorfield20:08:26

OK then probably the easiest way to make a JAR from beholder is to use depstar, since beholder doesn't have a build script or any aliases for that.

Jacob Emcken20:08:26

to figure out what that is

seancorfield20:08:42

Here's the steps you need:

(! 1026)-> git clone [email protected]:nextjournal/beholder.git
Cloning into 'beholder'...
...
(! 1027)-> cd beholder/
(! 1028)-> clojure -X:deps mvn-pom
(! 1029)-> clojure -Sdeps '{:aliases {:depstar {:deps {com.github.seancorfield/depstar {:mvn/version "2.1.278"}}}}}' -X:depstar hf.depstar/jar :jar beholder.jar
Building thin jar: beholder.jar
Processing pom.xml for {beholder/beholder {:mvn/version "0.1.0"}}
(! 1030)-> clojure -X:deps mvn-install :jar '"beholder.jar"'
Installing beholder.jar 
Installed to /Users/sean/.m2/repository/beholder/beholder/0.1.0

seancorfield20:08:55

(edited to show actual commands and results)

seancorfield21:08:45

Then you can depend on it (via lein or here in a CLI REPL):

(! 1033)-> clj -Sdeps '{:deps {beholder/beholder {:mvn/version "0.1.0"}}}'
Clojure 1.10.3
user=> (require 'nextjournal.beholder)
nil
user=> (nextjournal.beholder/watch prn ".")
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See  for further details.
#object[io.methvin.watcher.DirectoryWatcher 0x65bb9029 "io.methvin.watcher.DirectoryWatcher@65bb9029"]
user=> (spit "test.txt" "Hello")
nil
user=> {:type :create, :path #object[sun.nio.fs.UnixPath 0x69ee6735 "/Users/sean/clojure/fresh/./test.txt"]}

dominicm21:08:18

beholder officially uses https://github.com/applied-science/deps-library for it's jars/release process. So that's probably the supported path.

dominicm21:08:49

That includes the install step too

seancorfield21:08:38

The beholder project only seemed to have a :release alias so I wasn't sure what would be needed without also tracking down that library and learning about it 🙂

seancorfield21:08:54

@jacob429 Hope the above gets you going...

dominicm21:08:56

I hadn't heard of it before, but searched for "release.edn" on github and it came up 🙂

dominicm21:08:07

Oh, so it's actually as simple as clj -M:release install

seancorfield21:08:24

(pity there's no docs in beholder or its deps.edn file to make that clear since they're using a deps/release process that is not common/mainstream 🙂 )

dominicm21:08:13

Is there a standard release process yet? (depstar doesn't count)

seancorfield21:08:12

I think depstar is the most widely used JAR builder for deps.edn-based projects currently? But I hope it will be able to go away once tools.build's uber task does more merging stuff.

winsome21:08:35

I'd like to have deps.edn be my source of truth and use it to generate my pom.xml - is there a way to specify what should go in the <scm> tag? Right now cljdocs integration is broken because I don't have a source link in there.

winsome21:08:56

Oh, I'm using depstar, btw, with :sync-pom true

seancorfield21:08:04

@winsome that's why clj-new generates a fully-fledged pom.xml into new projects.

winsome21:08:31

Can I use clj-new on an existing project, or is that just like lein new?

seancorfield21:08:18

It's just like lein new. But you could use it to create a new project somewhere, with the same qualified project name that your current project has, and then copy the generated pom.xml file into your project.

seancorfield21:08:58

I'm working on deps-new which will be able to overlay new files into existing projects (and is much, much simpler to write new templates for).

winsome21:08:13

That sounds good, thanks. And deps-new is a great idea!

seancorfield21:08:30

Adding a full-featured pom.xml file is a good new feature for deps-new -- I'll create an issue.

winsome21:08:14

yeah, it's something I never think of until it's release time, which can be quite distant from creation time (never in most cases :p)

Jacob Emcken21:08:01

@dominicm Thanks clojure -M:release install seemed to work

salam22:08:07

is there a way to configure the clj/`clojure` commands globally so that we can apply a particular command line argument to all clj/`clojure` calls? for example, i would like to set --report stderr globally so that i don't have to change each and every existing call to these commands.

salam22:08:54

ok. thanks, Alex.

Alex Miller (Clojure team)22:08:54

in general, I think -J-Dclojure.main.report=stderr is better for the Clojure CLI as it composes better with main args and -X etc

Alex Miller (Clojure team)22:08:50

you could make an alias with :jvm-opts ["-Dclojure.main.report=stderr"] that could be combined with any other alias

Alex Miller (Clojure team)22:08:59

this question is for default jvm opts https://ask.clojure.org/index.php/7834/support-default-jvm-opts if you want to vote for it (which would let you do the thing above more broadly)

Alex Miller (Clojure team)22:08:31

but I think adding such a thing needs much more consideration in how it combines

salam22:08:21

understood. i'll go with the alias approach for now as we already have :dev alias that's referenced at every call site to clojure. thank you.