<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">>
  <channel>
    <title>leiningen on Daniel Compton</title>
    <link>https://danielcompton.net/tags/leiningen/index.xml</link>
    <description>Recent content in leiningen on Daniel Compton</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 25 Jul 2022 13:30:36 +1200</lastBuildDate><atom:link href="https://danielcompton.net/tags/leiningen/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Leiningen dependency commands in Clojure CLI</title>
      <link>https://danielcompton.net/snippets/leiningen-dependency-commands-clojure-cli</link>
      <pubDate>Mon, 25 Jul 2022 13:30:36 +1200</pubDate>
      
      <guid>https://danielcompton.net/snippets/leiningen-dependency-commands-clojure-cli</guid>
      <description>At work, we have recently converted our projects to the Clojure CLI and deps.edn. There were a few commands from Leiningen that I needed to find an equivalent for when working with dependencies.
Download all dependencies Often in a CI environment, you want to download all of the dependencies for a project before building the project. In Leiningen, you can use lein deps to do this.
You can use clojure -P to Prepare the project with the Clojure CLI.</description>
      <content:encoded><![CDATA[<p>At <a href="https://whimsical.com/">work</a>, we have recently converted our projects to the Clojure CLI and <code>deps.edn</code>. There were a few commands from Leiningen that I needed to find an equivalent for when working with dependencies.</p>
<h2 id="download-all-dependencies">Download all dependencies</h2>
<p>Often in a CI environment, you want to download all of the dependencies for a project before building the project. In Leiningen, you can use <code>lein deps</code> to do this.</p>
<p>You can use <code>clojure -P</code> to <strong>P</strong>repare the project with the Clojure CLI. This downloads libs and caches the classpath.</p>
<p>Note that you should avoid running <code>clojure -P</code> in parallel on new environments (like CI). When running <code>clojure -P</code> for the first time, it will set up files in <code>~/.clojure</code> and clone gitlibs. If you run multiple processes doing this simultaneously, you can get race conditions that throw errors.</p>
<h2 id="view-the-dependency-tree">View the dependency tree</h2>
<p>When debugging dependency issues, it&rsquo;s often helpful to see which library pulled in a transitive dependency.</p>
<p>Leiningen can print the dependency showing the resolved transitive dependencies.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">$ lein deps :tree
</span></span><span class="line"><span class="cl"> <span class="o">[</span>clansi <span class="s2">&#34;1.0.0&#34;</span><span class="o">]</span>
</span></span><span class="line"><span class="cl"> <span class="o">[</span>clj-kondo <span class="s2">&#34;2022.03.09&#34;</span> :scope <span class="s2">&#34;test&#34;</span><span class="o">]</span>
</span></span><span class="line"><span class="cl"> <span class="o">[</span>babashka/fs <span class="s2">&#34;0.1.2&#34;</span> :scope <span class="s2">&#34;test&#34;</span><span class="o">]</span>
</span></span><span class="line"><span class="cl"> <span class="o">[</span>cheshire <span class="s2">&#34;5.10.2&#34;</span> :scope <span class="s2">&#34;test&#34;</span><span class="o">]</span>
</span></span><span class="line"><span class="cl"> <span class="o">[</span>com.fasterxml.jackson.dataformat/jackson-dataformat-cbor <span class="s2">&#34;2.12.4&#34;</span> :scope <span class="s2">&#34;test&#34;</span> :exclusions <span class="o">[[</span>com.fasterxml.jackson.core/jackson-databind<span class="o">]]]</span>
</span></span><span class="line"><span class="cl"> <span class="o">[</span>com.fasterxml.jackson.dataformat/jackson-dataformat-smile <span class="s2">&#34;2.12.4&#34;</span> :scope <span class="s2">&#34;test&#34;</span> :exclusions <span class="o">[[</span>com.fasterxml.jackson.core/jackson-databind<span class="o">]]]</span>
</span></span><span class="line"><span class="cl"> <span class="o">[</span>tigris <span class="s2">&#34;0.1.2&#34;</span> :scope <span class="s2">&#34;test&#34;</span><span class="o">]</span>
</span></span><span class="line"><span class="cl"> <span class="o">[</span>com.cognitect/transit-clj <span class="s2">&#34;1.0.324&#34;</span> :scope <span class="s2">&#34;test&#34;</span><span class="o">]</span>
</span></span><span class="line"><span class="cl"> <span class="c1"># ...</span>
</span></span></code></pre></div><p><code>clojure</code> has a similar command, though with a slightly different output. In contrast to Leiningen, <code>clojure</code> prints the entire dependency tree. Dependencies <code>clojure</code> didn&rsquo;t select get an <code>X</code> in front of them, and a short reason like <code>:older-version</code> or <code>:excluded</code>. These views can be helpful when debugging why you didn&rsquo;t get the version you expected.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">$ clojure -Stree
</span></span><span class="line"><span class="cl">org.clojure/clojure 1.11.0
</span></span><span class="line"><span class="cl"> . org.clojure/spec.alpha 0.3.218
</span></span><span class="line"><span class="cl"> . org.clojure/core.specs.alpha 0.2.62
</span></span><span class="line"><span class="cl">org.clojure/java.classpath 1.0.0
</span></span><span class="line"><span class="cl">clansi/clansi 1.0.0
</span></span><span class="line"><span class="cl">org.clojure/data.json 2.4.0
</span></span><span class="line"><span class="cl">org.slf4j/slf4j-simple 2.0.0-alpha1
</span></span><span class="line"><span class="cl"> . org.slf4j/slf4j-api 2.0.0-alpha1
</span></span><span class="line"><span class="cl">org.owasp/dependency-check-core 7.0.2
</span></span><span class="line"><span class="cl"> . us.springett/cpe-parser 2.0.2
</span></span><span class="line"><span class="cl"> X org.slf4j/slf4j-api 1.7.30 :older-version
</span></span><span class="line"><span class="cl"> . com.vdurmont/semver4j 3.1.0
</span></span><span class="line"><span class="cl"> X org.slf4j/slf4j-api 1.7.36 :older-version
</span></span></code></pre></div><h2 id="view-the-classpath">View the Classpath</h2>
<p>While dependency trees can help track down dependency problems, sometimes you need to see the actual classpath.</p>
<p>Tip: I like to use <code> | tr ':' '\n' | sort</code> to get a sorted list of the classpath entries.</p>
<p>You can do this in Leiningen:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">lein classpath
</span></span><span class="line"><span class="cl"><span class="c1"># or</span>
</span></span><span class="line"><span class="cl">lein classpath <span class="p">|</span> tr <span class="s1">&#39;:&#39;</span> <span class="s1">&#39;\n&#39;</span> <span class="p">|</span> sort
</span></span></code></pre></div><p>With <code>clojure</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">clojure -Spath
</span></span></code></pre></div><p>Both Leiningen and <code>clojure</code> have more commands for dependencies; you can read more about them at <a href="https://clojure.org/reference/dep_expansion">Dep Expansion</a>, <a href="https://clojure.org/reference/deps_and_cli">Deps and CLI</a>, and <a href="https://github.com/technomancy/leiningen/blob/ee6b88beb8a82ae11605bc8f3e20c22f1a5ca886/src/leiningen/deps.clj#L109-L151">lein deps</a>.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
