lein-autodoc with Leiningen 2

2019-05-21 16:28发布

问题:

I am attempting to use lein-autodoc, because I believe it to be the preferred documentation generator for Clojure. I have added :dev-dependencies [[lein-autodoc "0.9.0"]] to my project definition as per the instructions on the lein-autodoc github page.

Running lein deps runs without issue, however lein autodoc fails, claiming that autodoc is not a task.

I suspect the issue is that lein-autodoc is set up to work with leiningen 1. However, I'm using leiningen 2. Is there an alternate way I should be calling lein with autodoc? Or is the lein-autodoc package not set up to work with lein 2? If not, is there another preferred lein2-compatible documentation generation option?

EDIT:

After Cubic's hint below, I created ~/.lein/profiles.clj as follows:

{:user {:plugins [[lein-autodoc "0.9.0"]]}}

Now, running lein autodoc results in the following:

$ lein autodoc
Exception in thread "main" java.lang.IllegalAccessError: sh does not exist
    at clojure.core$refer.doInvoke(core.clj:3778)
    at clojure.lang.RestFn.applyTo(RestFn.java:139)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$load_lib.doInvoke(core.clj:5279)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$load_libs.doInvoke(core.clj:5298)
    (...)

This suggests perhaps autodoc is not compatible with Lein 2? If not, is there any doc system that works with Lein 2?

回答1:

autodoc used to be the more common documentation generator, but these days it is mostly just used for Clojure itself (and is optimized for the task). I highly recommend that you use codox instead. It is excellent. You can see it in action in one of my own projects here

(I know this has been said in the other answer, but for my answer to be complete I need to add it anyways)

Also, in leiningen 2 there is no :dev-dependencies key. Instead, there is a :dev profile. Take a look at the Leiningen profile documentation for more information. In this case, all you need to do is add a :plugins key to your project or global user profile with the plugins you want (like codox, autodoc, etc).



回答2:

There is no :dev-dependencies in lein 2, you'd have to do it with profiles.

I'm not sure whether autodoc actually works with lein 2 though. Keep in mind that clojure and it's environment grows pretty fast, and there's lots of outdated information out there.