4

How to generate documentation for mix project? How it can do it?

The procedure for working with the Elixir mix-project:

  • I generate a project by mix new greeter command.
  • I add a block of comments in the greeter.ex file.
  • I add dependencies to the mix.exs file.
  • I try to generate documentation by mix docs command.

mix help can not provide docs task in a list of possible options:

mix                   # Runs the default task (current: "mix run")
mix app.start         # Starts all registered apps
mix app.tree          # Prints the application tree
mix archive           # Lists installed archives
mix archive.build     # Archives this project into a .ez file
mix archive.install   # Installs an archive locally
mix archive.uninstall # Uninstalls archives
mix clean             # Deletes generated application files
mix cmd               # Executes the given command
mix compile           # Compiles source files
mix deps              # Lists dependencies and their status
mix deps.clean        # Deletes the given dependencies' files
mix deps.compile      # Compiles dependencies
mix deps.get          # Gets all out of date dependencies
mix deps.tree         # Prints the dependency tree
mix deps.unlock       # Unlocks the given dependencies
mix deps.update       # Updates the given dependencies
mix dialyzer          # Runs dialyzer with default or project-defined flags.
mix dialyzer.build    # Build the required plt(s) and exit.
mix dialyzer.clean    # Delete plt(s) and exit.
mix dialyzer.explain  # Display information about dialyzer warnings.
mix do                # Executes the tasks separated by comma
mix escript           # Lists installed escripts

When I run mix docs command I get a mix-message:

**(Mix) The task "docs" could not be found. Did you mean "do"?

Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  earmark 1.3.2
  ex_doc 0.20.2
  makeup 0.8.0
  makeup_elixir 0.13.0
  nimble_parsec 0.5.0
All dependencies are up to date

What is my mistake?

5 Answers5

9

The mix docs task is available with ExDoc. Make sure that you have the dependency installed. Make sure to check out the docs and install it properly. Then you'll be able to use the mix docs command.

This is how to install it:

  • Add it to your dependencies in mix.exs:

for Elixir >= 1.7:

def deps do
  [
    {:ex_doc, "~> 0.19", only: :dev, runtime: false},
  ]
end

Elixir < 1.7:


def deps do
  [
    {:ex_doc, "~> 0.18.0", only: :dev, runtime: false},
  ]
end
  • Run mix deps.get
  • Run mix docs

There are things you can configure in the project function of your mix file. Such as the name, source_url and homepage_url. Make sure to check out ExDoc's documentation for more details.

Concerning the "task could not be found" error, mix help lists tasks for the current environment. The default mix environment is :dev, and above ex_doc was added to the :dev environment. However, some projects use a :docs environment, instead of :dev.

Also, mix tasks can be provided by compilation, so you may need compile first (also respecting the environment, as above).

So, if the mix docs task is not listed by mix help or "could not be found", be sure to run mix compile and mix help in the environment of the ex_doc dependency. For example, run MIX_ENV=docs mix compile, then MIX_ENV=docs mix help or MIX_ENV=docs mix docs.

Richard Michael
  • 1,540
  • 16
  • 19
sbacarob
  • 2,092
  • 1
  • 14
  • 19
  • It should work like this, but for some reason it does not work. Elixir version is 1.8.2. My mix.exs file contains ( ``` def deps do [ {:ex_doc, "~> 0.19", only: :dev, runtime: false}, ]) ``` I try to do a description of https://elixirschool.com/en/lessons/basics/documentation/ material. I have done all you describe. Unfortunately, all this does not lead to the generation of documentation. – Anatolii Kosorukov May 23 '19 at 08:46
  • I read ExDoc documentation. I would like to see all options available when generating docs, run `mix help docs`. I can't - `** (Mix) The task "docs" could not be found. Did you mean "do"?` – Anatolii Kosorukov May 23 '19 at 08:53
3

I remove _build directory, remove all content of deps directory, remove mix.lock.

Then in a command line of mix-project I do commands:

  1. mix deps.clean --all
  2. mix deps.update --all
  3. mix deps.get --all

After that, I run mix docs and documentation was generated.

Command mix help docs print ExDoc documentation too.

1

This kind of error comes when we have a dependency which is available only for some environment like only :test or :dev so to fix this issue please make sure that particular dependency is available in required environment

{:ex_doc, ">= 0.0.0", runtime: false}

Update it like this and it should solve the issue.

Yatender Singh
  • 3,098
  • 3
  • 22
  • 31
0

If you installed ex_doc with

{:ex_doc, "~> 0.19", only: :dev, runtime: false},

It will not work if you are running in :prod mode. You need to remove only :dev from the line above.

-1

For my project mix do docs worked.

Catalyst
  • 29
  • 5