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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With