You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>As opposed to downloading required JAR files by hand (<em>unmanaged</em> dependencies), a <em>managed</em> dependency system automates fetching external libraries for a subproject. Tools like Coursier interpret the declared <code>ModuleID</code>, perform dependency resolution (expand all the transitive dependencies, and resolve any version conflicts to determine the exact versions), and download and cache the resulting artifacts, ensuring consistent JAR management.</p>
<p>As opposed to downloading required JAR files by hand (<em>unmanaged</em> dependencies), a <em>managed</em> dependency system automates fetching external libraries for a subproject. Tools like Coursier interpret the declared <code>ModuleID</code>, perform dependency resolution (expand all the transitive dependencies, and resolve any version conflicts to determine the exact versions), and download and cache the resulting artifacts, ensuring consistent JAR management.</p>
<p>This page explains the basics of library dependency management using sbt.</p>
213
-
<p>sbt uses <ahref="https://get-coursier.io/">Coursier</a> to implement managed dependencies, so if you're familiar with package managers like Coursier, npm, PIP, etc you won't have much trouble.</p>
<p>sbt will automatically resolve the dependencies and download the JAR files.</p>
225
-
<h3id="getting-the-right-scala-version-with-"><aclass="header" href="#getting-the-right-scala-version-with-">Getting the right Scala version with <code>%%</code></a></h3>
226
-
<p>If you use <code>organization %% moduleName % version</code>rather than <code>organization % moduleName % version</code>(the difference is the double <code>%%</code>after the <code>organization</code>), sbt will add your project's binary Scala version to the artifact name. This is just a shortcut. You could write this without the <code>%%</code>:</p>
<p>Assuming the <code>scalaVersion</code> for your build is 3.x, the following is identical (note the double <code>%%</code>after<code>"toolkit"</code>):</p>
<p>The idea is that many dependencies are compiled for multiple Scala versions, and you'd like to get the one that matches your project to ensure binary compatibility.</p>
233
-
<h2id="tracking-dependencies-in-one-place"><aclass="header" href="#tracking-dependencies-in-one-place">Tracking dependencies in one place</a></h2>
234
-
<p><code>.scala</code>files under <code>project</code>becomes part of the build definition, which we can use to track dependencies in one place by creating a file named <code>project/Dependencies.scala</code>.</p>
235
-
<pre><codeclass="language-scala">// place this file at project/Dependencies.scala
val toolkitTest = "org.scala-lang" %% "toolkit-test" % toolkitV
246
257
end Dependencies
247
258
</code></pre>
248
-
<p>The<code>Dependencies</code>object will be available in <code>build.sbt</code>. To make it easier to use the <code>val</code>s defined in it, import <code>Dependencies.*</code>in your build.sbt file.</p>
0 commit comments