Reputation: 309
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!
Upvotes: 8
Views: 1042
Reputation: 159855
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(...)
}
Upvotes: 7