technomancy/leiningen — pull request #1081 by trptcolin (2013-03-20 04:33:51+00:00)
Title: show-profiles/with-profile asymmetry (please take a close look before merging)

Given a `~/.lein/profiles.clj` with this:

```clojure
{:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}}
```

`lein show-profiles` includes the 1.4 profile in both project and non-project scenarios. `lein with-profile` behaves as I'd hoped inside of a project:

```
colin:foobar/ $ lein with-profile 1.4 repl
Performing task 'repl' with profile(s): '1.4'
nREPL server started on port 61740
REPL-y 0.1.10
Clojure 1.4.0
...
```

but *not* outside a project:
```
colin:/tmp/ $ lein with-profile 1.4 repl
Performing task 'repl' with profile(s): '1.4'
Warning: profile :1.4 not found.
Warning: profile :1.4 not found.
Exception in thread "main" java.lang.NoClassDefFoundError: clojure/main
...
```

This seems broken, in that `show-profiles` seems to promise the profile's availability, but `with-profile` won't let you use it.

Being a profile dummy, my first thought was to add a `(project-with-profiles)` call to [this pipeline in set-profiles](https://github.com/technomancy/leiningen/blob/63598681727894fb62035a00c5e7ad31d6855168/leiningen-core/src/leiningen/core/project.clj#L550-L553). That worked for my use case, but it broke 17 profile-merging tests. I didn't dig into what the failures meant in any depth, so I guess it's possible that *was* the right thing to do, but I got skeered.

So the patch in this branch is less invasive, mostly just affecting the `with-profile` task itself, plus a consistency tweak that I *think* is safe for `show-profiles`. But I don't know that it's any safer, hence the warning at the top of this. What could go wrong? I'm not sure.

Worst case, if there's a good reason user/system/other profiles must be disallowed in non-project situations using `with-profile`, we should update the `show-profiles` task to omit these profiles as well.