We are going to try out the different command line options available as we continue our journey into the Clojure CLI tools..
We explore the different ways to running Clojure code, from a single expression to a full project. We include examples of aliases for optional configuration and combining aliases to create specific configurations when running a project. Finally we will see how to diagnose a project and understand potential sources of conflicts.
Please see earlier articles in thise series for background:
clojure -A:test will add test to the search path and include the org.clojure/test.check library.
clojure -A:runner will add the com.congnitect/test-runner library from GitHub and then run with the cognitect.test-runner as the main namespace. clojure will also include configuration from the test build configuration.
The practicalli/first-cli-app does not yet define a dev build, so no additional configuration is added when using the -A:runner alias.
We have already been combining configurations and so its not surprising that we can combine aliases too.
The practicalli/study-group-guide defines several aliases
The command should execute without error and if so no output is returned. So open the deps.edn file in the project and check the dependency has been added.
It does seem easier to simply edit the deps.edn file and add project dependencies, especially as the code may need formatting. If you are working with a bigger project then using the CLI to add a dependency to an existing deps.edn project configuration could be a convenient way to share new dependencies between teams or others who want to use your project, reducing the risk of copy/paste errors or adding different versions.
It could be useful to create a script that populates a project deps.edn file with all the same depencencies. What happens if you try add the same dependency but with different versions? Maybe using clojure - script-to-set-dependencies.sh
Error: no deps.edn file
if you are not in a project with a deps.edn file then the call to clojure -Sdeps ,,, will fail with the following error
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
clojure -Stree in a project directory will show all the library dependencies you added to the project along with all the depencencies that each of those libraries have.
-Stree is a very useful diagnostic tool when you have clashes between dependencies, or more likely the version of dependencies that the libraries you added as dependences have as dependencies (I think that needs a diagram).
In the practicalli/first-cli-app we can see that the org.clojure/clojure library we added has two libraries as its dependencies.
In the figwheel-main project we saw that reagent/reagent library had 4 additional dependencies it relied upon. If one of those dependencies were causing an issue, we could define an exclusion on the reagent/reagent dependency entry
The config_paths configuration shows which deps.edn files are used to build up the configuration, very useful for debugging missing or incorrect configuration (if its pulling in unexpected files into the configuration).
TODO: try with a figwheel-main project
-Sdescribe - showing the configuration and where it came from
The -Sdescribe option provides a simple way to understand where clojure is getting its configuration from and what the key parts of that configuration are.