Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional dependency in SBT

Tags:

sbt

Maven has the optional dependency concept. Search of the SBT documentation for optional dependencies finds only "However, sometimes we have optional dependencies for special features.".

How can I declare an optional dependency in SBT?

like image 590
Alexey Romanov Avatar asked Jun 17 '16 13:06

Alexey Romanov


People also ask

What is optional dependency?

Optional dependencies are used when it's not possible (for whatever reason) to split a project into sub-modules. The idea is that some of the dependencies are only used for certain features in the project and will not be needed if that feature isn't used.

Which is the correct way to add dependencies in SBT file?

Library dependencies can be added in two ways: unmanaged dependencies are jars dropped into the lib directory. managed dependencies are configured in the build definition and downloaded automatically from repositories.

What is provided dependency in SBT?

The “provided” keyword indicates that the dependency is provided by the runtime, so there's no need to include it in the JAR file. When using sbt-assembly, we may encounter an error caused by the default deduplicate merge strategy. In most cases, this is caused by files in the META-INF directory.

How do we specify library dependencies in SBT?

You can use both managed and unmanaged dependencies in your SBT projects. If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.


1 Answers

Unfortunately SBT documentation doesn't list all available scopes that map to Ivy Configurations, but the source code does: https://github.com/sbt/sbt/blob/0.13/ivy/src/main/scala/sbt/Configuration.scala

You can do this in the same way you scope a dependency for test, runtime or provided scope.

libraryDependencies += "group id" % "artifact id" % "version" % "optional"

or

libraryDependencies += "group id" % "artifact id" % "version" % Optional
like image 83
Alexander B Avatar answered Oct 16 '22 21:10

Alexander B