Fork me on GitHub

Is there a way to reference an alias that includes a :main-opts but does not actually call the -main when referenced? Similar to how you can use -X with an alias that includes an exec-fn but include it with -A and it won't call the function. Example in thread 🧵


% cat deps.edn 
 {:main {:extra-paths ["src"]
         :main-opts ["-m" "com.grzm.ex.main"]
         :exec-fn com.grzm.ex.main/exec}
  :exec {:extra-paths ["src"]
         :exec-fn com.grzm.ex.main/exec}}}

% cat src/com/grzm/ex/main.clj 
(ns com.grzm.ex.main)

(defn exec [_]
  (println "Hello, exec!"))

(defn -main [& _args]
  (println "Hello, main!"))

% clj -X:exec
Hello, exec!
Called exec-fn
% clj -A:exec
Clojure 1.10.3
Opened a repl with the appropriate classpath. Didn’t call exec-fn.
% clj -M:main
Hello, main!
Called -main.
% clj -A:main
WARNING: Use of :main-opts with -A is deprecated. Use -M instead.
Hello, main!
I’d like this last to open a repl, rather than call the -main Is there an alternative incantation that would do this that I’m missing?

Alex Miller (Clojure team)13:08:20

No, separate into two aliases


Cool. Thanks, @U064X3EF3!


(And thanks for calc-trace 🙂)