How do I add an SBT task to build.sbt that uses an external dependency?
e.g. I would like to write a task that utilises the AWS SDK client
libraryDependencies += "aws-sdk-name" % "etc. "%etc"
uploadTask := {
val s3Client = new AmazonS3Client(...);
s3Client.putObject(...)
}
However, there will understandably be compile errors because the dependency won't will be generated by sbt!
The docs for tasks are restricted to very simple use cases i.e. println(...).
A plugin seems a bit overkill to me for this so I am hoping there is another way.
Thanks!
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.
Like in almost every build system, SBT allows you to define library dependencies which are resolved automatically, so you don't have to download and package required libraries by yourself.
SBT Dependencies SBT is the most usual build tool for Scala projects. As a project gets more complex, it will increase the number of dependencies. And each dependency brings other dependencies, called transitive dependencies. Eventually, a project can suffer from the JAR dependency hell.
sbt
is a recursive build system, so just place the library dependency you need in your build into your project
folder:
your-project/
project/
build-dependencies.sbt
src/
main/ # etc.
build.sbt
libraryDependencies += "aws-sdk-name" % "etc. "%etc"
// Or in project/SomeBuildFile.scala
uploadTask := {
val s3Client = new AmazonS3Client(...);
s3Client.putObject(...)
}
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