I am defining an sbt task that needs to call code in a library. Here is a build.sbt file with what I've tried so far:
libraryDependencies ++= Seq("com.some.company" %% "some-lib" % "1.0.0")
val doSomething = taskKey[Unit]("does something")
doSomething := {
import com.some.company.function
function()
}
The imports do not work. How do I define a task that depends on code in an external library?
The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.
To add a dependency on a library that is an annotation processor, you must add it to the annotation processor classpath using the annotationProcessor configuration. That's because using this configuration improves build performance by separating the compile classpath from the annotation processor classpath.
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.
To build the .sbt
file itself in the root directory, SBT uses information in the project
directory. So put a build.sbt
in the project
directory and set the libraryDependencies
key there:
libraryDependencies ++= Seq("com.some.company" %% "some-lib" % "1.0.0")
So, to clarify, you now have two build.sbt
files:
./build.sbt
./project/build.sbt
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