technomancy / leiningen

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

Explain profiles / deps in debug mode? #2703

Open spacegangster opened 4 years ago

spacegangster commented 4 years ago

Dear Leiningen team, big thanks for all the great work you do.

I have a java source file in my codebase and I was playing around with lein javac. If I run it after lein clean it somehow pulls Clojure code that requires that java class from the source file. So it throws a ClassNotFoundException as the class isn't compiled yet. After lots of experimentation I managed to successfully run lein with-profile base javac. This, apparently doesn't pull and Clojure code, so javac compiles successfully.

Maybe DEBUG mode could have been more helpful here if it told me which profiles it used.

Output from lein with-profile base javac looks like:

export DEBUG=true
lein javac                                                
Leiningen's classpath: :/usr/local/Cellar/leiningen/2.9.4/libexec/leiningen-2.9.4-standalone.jar                                                                       
Applying task [with-profile base javac] to []                                                                                                                          
Applying task javac to nil                                                                                                                                             
Running javac with [-source 10 -target 10 -Xlint:all,-options,-path -Werror -verbose @/var/folders/tm/s0q62bts2z37l_f_47h2g_lh0000gn/T/.leiningen-cmdline12610930977279
164786.tmp] 

Output from plain lein javac

lein javac                                              
Leiningen's classpath: :/usr/local/Cellar/leiningen/2.9.4/libexec/leiningen-2.9.4-standalone.jar
Applying task javac to []
Running javac with [-source 10 -target 10 -Xlint:all,-options,-path -Werror -verbose @/var/folders/tm/s0q62bts2z37l_f_47h2g_lh0000gn/T/.leiningen-cmdline17469967280683
045361.tmp]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/spacegangster/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/spacegangster/.m2/repository/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Exception in thread "main" Syntax error compiling at (app/conversion_functions.clj:1:1).
...
Caused by: java.lang.ClassNotFoundException: java_guest.GcalDateTime
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
        at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:69)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:566)
        at clojure.lang.DynamicClassLoader.loadClass(DynamicClassLoader.java:77)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:374)
        at clojure.lang.RT.classForName(RT.java:2211)
        at clojure.lang.RT.classForNameNonLoading(RT.java:2224)
        at app.conversion_functions$eval39260$loading__6721__auto____39261.invoke(conversion_functions.clj:1)
        at app.conversion_functions$eval39260.invokeStatic(conversion_functions.clj:1)
        at app.conversion_functions$eval39260.invoke(conversion_functions.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:7177)
        at clojure.lang.Compiler.eval(Compiler.java:7166)
        at clojure.lang.Compiler.load(Compiler.java:7636)

project.clj looks like


(defproject app "20-10--0.5.0"
  :dependencies
    [[org.clojure/clojure    "1.10.1"]]

  :min-lein-version "2.5.3"
  :javac-options ["-source" "10"
                  "-target" "10"
                  "-Xlint:all,-options,-path"
                  "-Werror"
                  "-verbose"]

  :source-paths ["app/src"]
  :java-source-paths ["java_guest/src"] ; hosts Google's RFC-3339 DateTime implementation
  :clean-targets ^{:protect false} ["target"]
  :profiles
  {:debug {:debug true :injections [(prn (into {} (System/getProperties)))]}
   :dev
   {:dependencies [[org.clojure/tools.namespace "0.2.10"]
                   [org.clojure/tools.nrepl     "0.2.13"]
                   [org.clojure/tools.trace     "0.7.10"]
                   [org.slf4j/slf4j-simple      "1.7.25"]]
    :prep-tasks ["javac" "compile"]

    :source-paths ["dev"]

    :plugins      [[lein-doo "0.1.8"]
                   [lein-pdo "0.1.1"]]}}
  :main app.facade

  :aot [clojure.tools.logging.impl
        app.facade])

So, would be cool if instead of:

Applying task [with-profile base javac] to []                                                                                                                          
Applying task javac to nil  

I would get a list of profiles and the merged deps / source-paths and ideally a reason why it is this way. And maybe a reference of a doc section to read. I think this would be big for you as well as this eliminates lots of potential issues and fruitless discussions.


P.S. again – big thanks for your work. Using lein for many years, and so far was satisfied. I look forward to be supporting lein more in the future as soon as I'll have some income back again.

technomancy commented 2 years ago

I think this is a good idea if anyone wants to submit a patch to implement it.

faisalhasnain commented 2 years ago

I am getting the same issue

faisalhasnain commented 2 years ago

Removing the :source-paths from :dev profile fixed the issue, but its a deal breaker

faisalhasnain commented 2 years ago

This workaround resolved my issue: https://github.com/technomancy/leiningen/issues/1477#issuecomment-960624941