Fork me on GitHub
#leiningen
<
2020-11-20
>
herald13:11:25

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)?

mikerod15:11:05

@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

mikerod15:11:16

so at runtime, you could use something liek to gain access to it

mikerod15:11:20

not sure if that is too late for you or not

herald15:11:56

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.

herald15:11:54

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 ( "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.

herald15:11:50

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.

herald15:11:50

Perhaps I need to use eval-in-project

herald15:11:30

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?

mikerod18:11:33

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

mikerod18:11:44

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

mikerod18:11:50

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

mikerod18:11:28

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

mikerod18:11:34

to not clash with those that use it

herald20:11:31

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.

👍 3