Fork me on GitHub
Martynas Maciulevičius14:02:38

Is there a way to run part of my project as a babashka script? The only examples that I found in the repository are the ones that either import some kind of a library or are self-contained in the source file. What if I have many sources and I want to run it from sources? Edit: I found the bb --init but it's not enough because I have quite a bit of sources. Is there a way to form the "classpath-loadpath" automatically? (also I use leiningen for the project and I'm not familiar with edn format)


@U028ART884X You can use bb -m to execute a function if foo/bar.clj is on your classpath

Martynas Maciulevičius15:02:51

Classpath... does it need to be specified in edn? Because my project is in leiningen. Probably that's a problem.


you can specify it manually with bb -cp src -m

Martynas Maciulevičius15:02:04

Ok. I'll try it. But I think I have some libraries that babashka won't run. But I want to firstly run something. Thanks.


lein classpath spits the classpath to a file - there is a way to wiggle that in to one command i’m sure


What you can also do if you want to use libraries that are brought in by leiningen:

lein classpath > .classpath
bb -cp $(cat .classpath) -m

Martynas Maciulevičius15:02:52

It worked. Now I have to decide what to do with all of it...

Type:     java.lang.Exception
Message:  Could not find namespace: java-time.


@U028ART884X It seems the classpath wasn't set properly, else you would see a different error, now it just can't find the java-time namespace since it's not on the classpath


is your project public?

Martynas Maciulevičius15:02:18

No, my project is internal to the company. But well. I've successfully hit a snag 😄 :

Type:     java.lang.Exception
Message:  Unable to resolve classname: java.lang.reflect.Field
Location: java_time/util.clj:3:3
But the trick with leiningen classpath worked really well. Thanks.


nice. yeah, this class isn't available in bb (yet). The java.time package is, so if you can avoid this library maybe that would help.


let me try to see what's needed to add compatibility with this lib

Martynas Maciulevičius15:02:04

It's not important, I think. I think that I import too much where I could split my namespaces.


OK. I think I was almost there, but java-time uses deftype which is one thing that bb can't handle (yet). If those would be records, then it would run.

😉 1

There are a couple of other java.time clojure libraries that do work with babashka, e.g. cljc-time

Martynas Maciulevičius15:02:25

Thanks. I don't want to push anybody into doing anything. I wanted to also try out the script runner. I'll try that time lib if I'll need time.