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)?
@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
so at runtime, you could use something liek <http://clojure.java.io/resource|clojure.java.io/resource>
to gain access to it
not sure if that is too late for you or not
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.
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.
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.
Perhaps I need to use eval-in-project
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?
@regen when the project tasks are being ran - you likely wont’ have any dependenices on the classpath
yes :eval-in-project
is a mechanism to get teh classpath of the project active
but not sure ho you may end up using it for this
as far as not overwriting, I think you should just be careful with how you name it in the dependency
to not clash with those that use it
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.