Fork me on GitHub
#leiningen
<
2018-03-16
>
colindresj16:03:53

I seem to be having an issue with lein including some unwanted dependencies into my classpath. For example, in my project.clj I’ve got :source-paths set to ["src"] and lein classpath includes my test directory in there. My test profile does have :source-paths as ["src" "test"], but even a lein with-profile -test classpath I’m still seeing the test directory in the classpath. Any ideas why this might be happening?

mikerod17:03:41

@colindresj do you have it in your :dev profile as well?

mikerod17:03:33

Really, do you have it coming from any of these other default profiles [:base :system :user :provided :dev] mentioned in https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md#default-profiles

colindresj17:03:28

I don’t have it in :dev or :user, and haven’t specified any of the others

colindresj17:03:43

Even doing lein with-profile -base,-system,-user,-provided,-dev classpath | tr ":" "\n" gives me something I don’t expect (including my test dir still being there)

colindresj17:03:15

Just asked a coworker to do the same and it’s happening for him as well

mikerod18:03:16

@colindresj just for completeness, perhaps make a profile, called :trial like

:trial {:source-paths ^:replace ["src"]}
then lein with-profile trial classpath

colindresj18:03:13

Here’s the first couple lines of my output @mikerod

mikerod18:03:08

@colindresj that’s with doing a profile like I mentioned above?

mikerod18:03:36

interesting, makes me think that classpath ignores the given profiles

mikerod18:03:44

I’d have to look at that a bit closer, doesn’t seem ideal

colindresj18:03:54

That’s possible

colindresj18:03:19

I actually ran into this because a different tool is using the output of lein classpath and I was getting some weird results, so I started digging

mikerod18:03:58

Basically end up in this

(defn get-classpath
  "Return the classpath for project as a list of strings."
  [project]
  (for [path (concat (:test-paths project)
                     (:source-paths project)
                     (:resource-paths project)
                     [(:compile-path project)]
                     (checkout-deps-paths project)
                     (for [dep (resolve-managed-dependencies
                                :dependencies :managed-dependencies project)]
                       (.getAbsolutePath dep)))
        :when path]
    (normalize-path (:root project) path)))

mikerod18:03:13

Looks like it will include :test-paths too

mikerod18:03:18

maybe that is your problem

mikerod18:03:27

maybe you have :test-paths at the root of the project.clj

colindresj18:03:33

Let me check

mikerod18:03:42

if you make a profile like :trial and put :test-paths ^:replace [] I think, that may help

mikerod18:03:05

Still may have to consider if you are using lein checkouts too though, since those may interfere as well

mikerod18:03:44

I think this impl does respect chosen profiles though

colindresj18:03:01

Replacing :test-paths fixes it for me

colindresj18:03:16

I don’t have :test-paths set in this project.clj, but I also have checkouts, so I’ll look through those

mikerod18:03:16

You may be able to squash checkouts with :checkout-deps-shares ^:replace [] in a profile too , but I’d have to experiment with that

mikerod18:03:38

I don’t know that is the correct thing at all, just off-the-head

mikerod18:03:47

Not able to experiment mysefl at the moment

colindresj18:03:10

That gives me a much smaller classpath, but still have test in there with :checkout-deps-shares ^:replace []

colindresj18:03:32

Maybe it’s a plugin that’s doing something with :test-paths?

colindresj18:03:54

Either way, I’m good for now just replacing :test-paths on a particular profile. Thanks @mikerod

mikerod18:03:25

Yeah. Hard to say I guess

mikerod18:03:51

Similar topics have came up in here recently

mikerod18:03:33

Seems like a few lein built in tasks would be nicer if they could give you a classpath/deps tree etc that is representative of the “production build”

mikerod18:03:51

Without manually tryin to fight off dev/test things getting in it.

colindresj18:03:17

Yeah for sure

greglook18:03:16

I’ve found using lein-cprint or lein-pprint really helpful debugging stuff like the above - you can do lein cprint :checkout-deps-shares to see the default, or lein with-profile uberjar cprint :checkout-deps-shares, etc.

mikerod19:03:19

@greg316 agreed that that can be a helpful tool

mikerod19:03:38

thanks for reminding me of passing keywords to it