0

I have use care where I have to process several clojure projects and find the imports of java libraries in each clojure namespace

I an invoking clj-kondo from my code for each .clj file as follows:

(def my-classpath
  ["/home/userxx/projects/clojure-dev/assetapi/libs/aws-java-sdk-sqs-1.12.120.jar"
   "/home/userxx/projects/clojure-dev/assetapi/libs/instaparse-1.4.8.jar"
   ;; ... all other JAR paths ...
   "/home/userxx/projects/clojure-dev/assetapi/libs/aws-java-sdk-cloudfront-1.12.120.jar"])

(def config
  {;; --- Top Level Keys ---

   :lint ["/home/userxx/projects/clojure-dev/assetapi/src/clojure/assetapi/handler.clj"]

   ;; Classpath at top-level
   :classpath my-classpath

   ;; Analysis flags under top-level :analysis
   :analysis {:java-class-usages true
              :java-class-definitions true
              :java-member-definitions true
             }

   ;; Output configuration at top-level
   :output {:analysis true ; Ensures analysis results are returned
            ;; :format :edn ; Optional: if you prefer edn output etc.
           }

   ;; The :config key is ONLY for merging external configs, if needed.
   ;; Do not put :output or :analysis under here for this purpose.

   })

;; Run clj-kondo programmatically
(def result (clj-kondo/run! config)) 

The classpath vector contains all the jars used in the clojure project that I am processing.

I know that the namespace I am passing in is using the java libraries and it including them in the namespace via (:import []) call in the source code and it also using it in source code. However, I am not seeing any java import or usages in the analysis that is returned

The analysis returns on these keys

 (:namespace-definitions :namespace-usages :var-definitions :var-usages)
enter code here

I expected to see java information in the analysis structure but I am not seeing it. I also do not see any java usage informaiton in (-> analysis :var-usages) . What do I need to fix ?

2
  • And your error/problem is? Commented Apr 3 at 20:09
  • The issue is that I expect analysis to have data for java class imports as the clojure source is importing hava classes. I do not see any java import information . Commented Apr 3 at 21:30

1 Answer 1

1

See this snippet:

(-> (with-in-str "(ns foo (:import [clojure.lang RT]))" (k/run! {:lint ["-"] :config {:analysis {:java-class-usages true}}})) :analysis :java-class-usages)

;;=> 

[{:end-row 1, :call nil, :lang :clj, :filename "<stdin>", :col 32, :class "clojure.lang.RT", :uri nil, :end-col 34, :import true, :row 1}]

So :java-class-usages returns the class reference with :import true indicating that it's an imported class.

Next time feel free to ask this question on Github Discussions in the clj-kondo repo or Clojurians Slack's clj-kondo channel for more visibility with clj-kondo users as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.