Fork me on GitHub
#leiningen
<
2019-10-03
>
ingesol10:10:17

Hi! I’m making a JAR from my client project, and before the actual zipping happens I want to move some files around, such that the dir layout in the JAR will be subtly different from that in the project structure. I tried using https://github.com/m0smith/lein-resource, but can’t seem to figure out how to make it operate on files in target folder before JAR task. Also, I think it only does copy, not move. Any ideas?

vemv10:10:35

in project.clj:

:profiles {:uberjar {:prep-tasks [...]}}
there you can invoke arbitrary custom tasks

mikerod13:10:07

you may find lein-shell helpful if you just want to do a few shell things to move stuff around pre-jar’ing. You can change the :source-paths or whatever to be a new tmp dir you make specifically for this changed layout too and that might help

mikerod13:10:36

:source-paths ^:replace ["jar-layout"]

mikerod13:10:43

you’d do that in a profile as well

ingesol13:10:47

that might work

mikerod13:10:20

(defproject org.example/my-tester "1.0.0"
  :plugins [[lein-shell "0.5.0"]]

  :aliases {"jar-build" ["do"
                         ["shell" "cp" "-r" "src" "jar-build/src"]
                         ["shell" "cp" "-r" "resources" "jar-build/src"]
                         ;; Do other changes you want to these new directory
                         ;; Add in any profiles you want active for `jar`.
                         ["with-profile" "jar-build" "jar"]]}
  
  :profiles {:jar-build {:source-paths ^:replace ["jar-build/src"]
                         :resource-paths ^:replace ["jar-build/resources"]}})
rough idea

mikerod13:10:25

but there are open questions

ingesol13:10:37

@U0LK1552A Currently I’m trying to use :jar-exclusions and :jar-inclusions because there are only a few changes I need in the file structure. So I try to copy them to the target folder and then exclude the original folder. But my settings don’t work

mikerod13:10:39

if you want this to build into the uberjar or install tasks, have to think about it a bit more

mikerod13:10:55

if you can just include/exclude things, that’d be ideal

ingesol13:10:32

Agree. But original resources are included anyway, no matter what changes I make. I’m suspecting I’m doing something very trivial wrong…

ingesol13:10:07

{:jar-exclusions [#"^src/scss/.*$"]
                     :jar-inclusions [#"^target/.*\.scss$"]
                     :resource       {:resource-paths
                                      [["src/scss"
                                        {:includes    [#".*\.sass"]
                                         :target-path "target/sass"}]]}}

mikerod13:10:37

I haven’t used the lein-resource, so don’t know about that part

mikerod13:10:48

you’re saying your :jar-exclusions aren’t being used though?

ingesol13:10:52

That part works, it copies files to the specified target

ingesol13:10:06

also tested this without the resource copying part, just ran jar task with files already in target folder

ingesol13:10:48

But sounds like you’re saying this is supposed to work, the way I’m expecting it here?

mikerod13:10:39

unless your regex are incorrect

mikerod13:10:58

inclusions and exclusions should work on the jar task specifically

ingesol13:10:01

I tested them elsewhere, semi-sure they work. But I guess they are the prime suspect

mikerod13:10:14

perhaps try making them more open to see if you get success

ingesol13:10:33

thanks so far!

mikerod13:10:05

like :jar-exclusions [#"scss/.*"]

mikerod13:10:18

like narrowing down if you have a regex problem or not

mikerod13:10:37

I haven’t tried excluding things from src or target specifically like that before, so I’m curious

mikerod13:10:47

no problem, but no fast answers here from me hah

ingesol13:10:56

yes, that’s pretty much what I’ve been doing so far. I’ll discuss it with some of my colleagues, maybe they’ll see it more clearly than I can

ingesol13:10:01

🙂

🎉 4
ingesol21:10:18

@U0LK1552A Ended up using most of your initial suggestion, works fine now. Thanks!

mikerod23:10:38

Cool. I’m glad it was helpful then.