technomancy / leiningen

Moved to Codeberg; this is a convenience mirror
https://codeberg.org/leiningen/leiningen
Other
7.29k stars 1.61k forks source link

test-paths are included on classpath when building uberjar #2808

Closed lverns closed 5 months ago

lverns commented 12 months ago

Describe the bug test-paths are included on classpath when building uberjar. I can see this by using the following reproduction steps, or by looking at the actual java command that lein creates to see that it includes test when building an uberjar

To Reproduce Steps to reproduce the behavior:

  1. run lein new app bugrepo
  2. cd bugrepo/
  3. create test/user.clj with echo "(ns user)" > test/user.clj and echo '(println "evaluating test/user.clj")' >> test/user.clj
  4. lein with-profile -user,-dev,-test,+uberjar uberjar or just lein uberjar

Actual behavior test/user.clj is evaluated while building the uberjar, as shown in the output

evaluating test/user.clj
Compiling bugrepo.core
Created <elided>/bugrepo/target/uberjar/bugrepo-0.1.0-SNAPSHOT.jar
Created <elided>/bugrepo/target/uberjar/bugrepo-0.1.0-SNAPSHOT-standalone.jar

Expected behavior I would expect that test/ would not be on the classpath when building the jar

Environment

technomancy commented 12 months ago

Sorry, I'm unable to reproduce this problem with the steps given. Is it possible you have a plugin installed in your user.clj which is triggering this?

lverns commented 12 months ago

I believe that I've disabled all plugins

$ ls ~/.lein/
profiles.clj.bak  repl-history  self-installs

Is there anywhere else they could be getting installed?

Here's the repo I'm working with in case there's something that could cause our templates to be different: https://github.com/lverns/repro-lein-2808

technomancy commented 12 months ago

Aha; I see now, I was running lein new foo instead of lein new app foo which meant that there was no :aot :all in the project.clj.

The core of this issue is that because of the AOT settings, the project is first compiled as-is, then the profile settings are applied, then the jar/uberjar is created. So the tests are still excluded from the artifact, but they are present during the AOT phase. We'll have to see if we can get the profile merged earlier on in the process to fix this.

technomancy commented 5 months ago

I think 6e17ebb fixes this.