technomancy/leiningen

test-paths are included on classpath when building uberjar

lverns opened this issue · 4 comments

lverns commented

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

  • Leiningen Version: 2.10.0
  • Leiningen installation method: manual
  • JDK Version: openjdk version "17.0.7" 2023-04-18
  • OS: Fedora 37

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

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

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.

I think 6e17ebb fixes this.