<?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>Deps.edn on Daniel Compton</title>
    <link>https://danielcompton.net/tags/deps.edn/index.xml</link>
    <description>Recent content in Deps.edn 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/deps.edn/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>&lt;p&gt;At &lt;a href=&#34;https://whimsical.com/&#34;&gt;work&lt;/a&gt;, we have recently converted our projects to the Clojure CLI and &lt;code&gt;deps.edn&lt;/code&gt;. There were a few commands from Leiningen that I needed to find an equivalent for when working with dependencies.&lt;/p&gt;
&lt;h2 id=&#34;download-all-dependencies&#34;&gt;Download all dependencies&lt;/h2&gt;
&lt;p&gt;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 &lt;code&gt;lein deps&lt;/code&gt; to do this.&lt;/p&gt;
&lt;p&gt;You can use &lt;code&gt;clojure -P&lt;/code&gt; to &lt;strong&gt;P&lt;/strong&gt;repare the project with the Clojure CLI. This downloads libs and caches the classpath.&lt;/p&gt;</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>
    
    <item>
      <title>Using classifiers with deps.edn</title>
      <link>https://danielcompton.net/snippets/how-to-use-classifier-in-tools-deps</link>
      <pubDate>Tue, 19 Jul 2022 12:10:36 +1200</pubDate>
      
      <guid>https://danielcompton.net/snippets/how-to-use-classifier-in-tools-deps</guid>
      <description>&lt;p&gt;One of Maven&amp;rsquo;s dependency management features is the &lt;a href=&#34;https://maven.apache.org/pom.html&#34;&gt;classifier&lt;/a&gt;. Classifiers let you create multiple different artifacts from the same POM. You might use this to publish variations with native libraries for each OS, or to support different Java versions. This is also how &lt;code&gt;sources&lt;/code&gt; and &lt;code&gt;javadoc&lt;/code&gt; artifacts are created.&lt;/p&gt;
&lt;p&gt;In Maven you can specify a dependency on a version with &lt;code&gt;&amp;lt;classifier&amp;gt;&lt;/code&gt; like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-xml&#34; data-lang=&#34;xml&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nt&#34;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nt&#34;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;io.netty&lt;span class=&#34;nt&#34;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nt&#34;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;netty-transport-native-epoll&lt;span class=&#34;nt&#34;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nt&#34;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;4.1.74&lt;span class=&#34;nt&#34;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nt&#34;&gt;&amp;lt;classifier&amp;gt;&lt;/span&gt;linux-x86_64&lt;span class=&#34;nt&#34;&gt;&amp;lt;/classifier&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nt&#34;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To specify this dependency with Clojure&amp;rsquo;s deps.edn, you need to use the &lt;a href=&#34;https://clojure.org/reference/deps_and_cli#_dependencies&#34;&gt;syntax&lt;/a&gt; &lt;code&gt;&amp;lt;group&amp;gt;/&amp;lt;artifact&amp;gt;$&amp;lt;classifier&amp;gt;&lt;/code&gt;:&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>One of Maven&rsquo;s dependency management features is the <a href="https://maven.apache.org/pom.html">classifier</a>. Classifiers let you create multiple different artifacts from the same POM. You might use this to publish variations with native libraries for each OS, or to support different Java versions. This is also how <code>sources</code> and <code>javadoc</code> artifacts are created.</p>
<p>In Maven you can specify a dependency on a version with <code>&lt;classifier&gt;</code> like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-xml" data-lang="xml"><span class="line"><span class="cl"><span class="nt">&lt;dependency&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;groupId&gt;</span>io.netty<span class="nt">&lt;/groupId&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;artifactId&gt;</span>netty-transport-native-epoll<span class="nt">&lt;/artifactId&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;version&gt;</span>4.1.74<span class="nt">&lt;/version&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;classifier&gt;</span>linux-x86_64<span class="nt">&lt;/classifier&gt;</span>
</span></span><span class="line"><span class="cl"><span class="nt">&lt;/dependency&gt;</span>
</span></span></code></pre></div><p>To specify this dependency with Clojure&rsquo;s deps.edn, you need to use the <a href="https://clojure.org/reference/deps_and_cli#_dependencies">syntax</a> <code>&lt;group&gt;/&lt;artifact&gt;$&lt;classifier&gt;</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-clj" data-lang="clj"><span class="line"><span class="cl"><span class="p">{</span><span class="ss">:deps</span> 
</span></span><span class="line"><span class="cl">  <span class="p">{</span><span class="nv">io.netty/netty-transport-native-epoll$linux-x86_64</span> 
</span></span><span class="line"><span class="cl">    <span class="p">{</span><span class="ss">:mvn/version</span> <span class="s">&#34;4.1.74.Final&#34;</span><span class="p">}}}</span>
</span></span></code></pre></div>]]></content:encoded>
    </item>
    
  </channel>
</rss>
