Library dependencies

The @@dependency block is used to show example code for how to configure a dependency on a library in a build tool, such as sbt.

@@dependency[sbt,Maven,Gradle] {
  group="com.typesafe.akka"
  artifact="akka-http_2.12"
  version="10.0.10"
}

Which will render as:

sbt
libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.0.10"
Maven
<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-http_2.12</artifactId>
  <version>10.0.10</version>
</dependency>
Gradle
dependencies {
  compile group: 'com.typesafe.akka', name: 'akka-http_2.12', version: '10.0.10'
}

The build tools for which to show a configuration snippet can be configured in the directive content. Recognized build tools are: sbt, Maven and Gradle. Each build tool snippet will be shown in a separate tab.

The library coordinates are defined via the group, artifact and version attributes. Optionally, scope and classifier attributes can also be defined if needed. Variables may be used inside attributes, for example $project.version$.

@@dependency[sbt,Maven,Gradle] {
  group="com.example"
  artifact="domain"
  version="0.1.0"
  scope="runtime"
  classifier="assets"
}

Which will render as:

sbt
libraryDependencies += "com.example" % "domain" % "0.1.0" % Runtime classifier "assets"
Maven
<dependency>
  <groupId>com.example</groupId>
  <artifactId>domain</artifactId>
  <version>0.1.0</version>
  <classifier>assets</classifier>
  <scope>runtime</scope>
</dependency>
Gradle
dependencies {
  runtime group: 'com.example', name: 'domain', version: '0.1.0', classifier: 'assets'
}

Multiple dependencies

It is also possible to render more than one dependency in a list. In that case library coordinates need to be appended with the same suffix. For example

@@dependency[sbt,Maven,Gradle] {
  group="com.example" artifact="domain" version="0.1.0"
  group2="com.example" artifact2="another-domain" version2="0.2.1"
}

will be rendered as:

sbt
libraryDependencies ++= Seq(
  "com.example" % "domain" % "0.1.0",
  "com.example" % "another-domain" % "0.2.1"
)
Maven
<dependency>
  <groupId>com.example</groupId>
  <artifactId>domain</artifactId>
  <version>0.1.0</version>
</dependency>
<dependency>
  <groupId>com.example</groupId>
  <artifactId>another-domain</artifactId>
  <version>0.2.1</version>
</dependency>
Gradle
dependencies {
  compile group: 'com.example', name: 'domain', version: '0.1.0',
  compile group: 'com.example', name: 'another-domain', version: '0.2.1'
}

Symbolic version numbers

When multiple dependencies always use the same version, symbolic version names can be shown. For example

@@dependency[sbt,Maven,gradle] {
  symbol="AkkaVersion"
  value="2.5.29"
  symbol2="AkkaHttpVersion"
  value2="10.1.0"
  group="com.typesafe.akka"
  artifact="akka-stream_$scala.binary.version$"
  version="AkkaVersion"
  group2="com.typesafe.akka"
  artifact2="akka-actor-typed_$scala.binary.version$"
  version2="AkkaVersion"
  group3="com.typesafe.akka"
  artifact3="akka-http_$scala.binary.version$"
  version3="AkkaHttpVersion"
}

will be rendered as:

sbt
val AkkaVersion = "2.5.29"
val AkkaHttpVersion = "10.1.0"
libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-stream" % AkkaVersion,
  "com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion,
  "com.typesafe.akka" %% "akka-http" % AkkaHttpVersion
)
Maven
<properties>
  <akka.version>2.5.29</akka.version>
  <akka.http.version>10.1.0</akka.http.version>
</properties>
<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-stream_2.12</artifactId>
  <version>${akka.version}</version>
</dependency>
<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-actor-typed_2.12</artifactId>
  <version>${akka.version}</version>
</dependency>
<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-http_2.12</artifactId>
  <version>${akka.http.version}</version>
</dependency>
gradle
versions += [
  AkkaVersion: "2.5.29",
  AkkaHttpVersion: "10.1.0"
]
dependencies {
  compile group: 'com.typesafe.akka', name: 'akka-stream_2.12', version: versions.AkkaVersion,
  compile group: 'com.typesafe.akka', name: 'akka-actor-typed_2.12', version: versions.AkkaVersion,
  compile group: 'com.typesafe.akka', name: 'akka-http_2.12', version: versions.AkkaHttpVersion
}
The source code for this page can be found here.