tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
vemv 2021-02-12T10:09:21.265Z

how to run a random .clj file's -main that has no 3rd party dependencies or a deps.edn file? I tried clojure -M some_folder/the_file.clj, it loads the file but it doesn't run its -main

practicalli-john 2021-02-12T10:19:23.265100Z

Edit: sorry I read the question incorrectly. If you do add a deps.edn, then you can do this.. The -M flag specifies that the clojure command should call Clojure main in the project (as opposed to the -X flag that calls a qualified function) -m is required to state which namespace to run -main, the namespace that includes (defn -main ,,,) So from your example it would be clojure -M -m some-folder.the-file

vemv 2021-02-12T10:22:07.265400Z

looks like in that case I'd have to add some-folder to the classpath. How to do it in an inline fashion?

practicalli-john 2021-02-12T10:25:47.265800Z

I was assuming that some_folder is under a src folder and you have a {:path ["src"]} in the deps.edn file Edit: can the -i flag be used for this, it loads a resource?

practicalli-john 2021-02-12T10:26:27.266Z

I believe you can use . Instead of src if there is no directory structure, but t that still requires a deps.edn file.

borkdude 2021-02-12T10:44:34.266300Z

@vemv this is a similar problem in babashka world. we invented this pattern for it: https://book.babashka.org/#main_file inspired by the Python way of doing things

👍 1
🙂 1
borkdude 2021-02-12T10:46:24.266600Z

So you can check using that condition if you are directly invoking this file or if you are referring to that file using the classpath

borkdude 2021-02-12T10:47:04.266800Z

But for clj this doesn't work. Some people also solve this using an env var in babashka: REPL=true -> don't invoke main at the bottom

vemv 2021-02-12T12:22:15.274400Z

clojure -M -i ./some-folder/the_file.clj -m the-file worked. Bit of an intrincate construction though :) Thank you both!

mbjarland 2021-02-12T14:51:54.275200Z

is there any way of using tools.deps code to retrieve the available list of versions for an artifact? This normally comes from the maven-metadata.xml file

agilecreativity 2021-02-23T00:17:21.032300Z

I build something like this once back in 2017. It allow you to fetch the version from maven https://github.com/agilecreativity/pom-versions @mbjarland

alexmiller 2021-02-12T14:53:15.275600Z

nothing in the tools.deps api, no

alexmiller 2021-02-12T14:53:43.276100Z

you could use the lower parts of the tools.deps api as an access point into maven apis to answer that question though

alexmiller 2021-02-12T15:05:37.276900Z

you basically want to use the Maven RepositorySystem API to make VersionRequests or VersionRangeRequests etc

mbjarland 2021-02-12T15:58:19.277500Z

@alexmiller ok thanks, that's the route I was heading, just wanted to make sure I wasn't reinventing the wheel

practicalli-john 2021-02-12T16:56:09.277700Z

Thanks for sharing the solution that worked for you.

borkdude 2021-02-12T17:07:10.277900Z

What's the point of having a -main btw if you are invoking this as a standalone file?

vemv 2021-02-12T17:34:26.278100Z

we are all a curious bunch :) This was a experimental CI-oriented script belonging to a big repo. Didn't seem to deserve its own deps.edn file. Indeed I could have unwrapped the main but there's some remote possibility of the top-level side-effect being executed by tooling (e.g. Eastwood, refactor-nrepl or t.n (refresh))