leiningen

N.B. The maintainers are on #leiningen on Libera chat IRC. Go there for direct support/bug reports.
uosl 2020-11-20T13:41:25.095200Z

One of the dependencies in my leiningen project has a resource packaged into the jar file at public/css/site.css. How do I get my project to copy this file into a specific folder when building (like from an alias)?

2020-11-20T15:29:05.096700Z

@regen I don’t think there is a direct way statically - there is lein-jar-copier out there - but it’s old and also too specific to jars - we actually internally made a lein-artifact-copier (internal to my company) that generalizes to this sort of isseu - but not released as public as of now. however, if the jar has public/css/site.css inside it - then that should be on your classpath when you have that dependency

2020-11-20T15:29:16.097200Z

so at runtime, you could use something liek <http://clojure.java.io/resource|clojure.java.io/resource> to gain access to it

2020-11-20T15:29:20.097500Z

not sure if that is too late for you or not

uosl 2020-11-20T15:31:56.098500Z

Thanks for the response! It's not too late; I'll try it out now. I'm pretty unfamiliar with Java so really scratching my head over this.

uosl 2020-11-20T15:34:54.099900Z

I'm trying to write a function in project.clj to read this file from the classpath and write it where I want it, then hope to be able to call that function from a lein alias. If I just add (println (<http://clojure.java.io/resource|clojure.java.io/resource> "public/css/site.css")) to the top of my project.clj, it will print nil (slurping will throw an error) when I run the project.

uosl 2020-11-20T15:38:50.101Z

Just so you know, public/css/site.css is the location of the file when I unzip the jar file of the dependency in .m2. I don't know if I need to add some kind of prefix to reference it from the other project.

uosl 2020-11-20T15:42:50.101300Z

Perhaps I need to use eval-in-project

uosl 2020-11-20T15:58:30.103300Z

Alright, I followed https://github.com/technomancy/leiningen/blob/stable/doc/PLUGINS.md#not-writing-a-plugin-%E6%97%A0%E4%B8%BA to call a function in my project namespace that does the io/resource and copies the file to where I want it. Last problem is there's a file in the project that happens to have the same exact path and name, and it seems that file overwrites the one from the dependency. I'm probably just going to rename the file, but is there a way around this?

2020-11-20T18:06:33.103900Z

@regen when the project tasks are being ran - you likely wont’ have any dependenices on the classpath

2020-11-20T18:06:44.104200Z

yes :eval-in-project is a mechanism to get teh classpath of the project active

2020-11-20T18:06:50.104500Z

but not sure ho you may end up using it for this

2020-11-20T18:07:28.105Z

as far as not overwriting, I think you should just be careful with how you name it in the dependency

2020-11-20T18:07:34.105200Z

to not clash with those that use it

uosl 2020-11-20T20:32:31.107900Z

Ok thanks. I'm going to see if I can create a PR to the Leiningen FAQ for this, as it wasn't very easy to figure out.

👍 1