Chapter 8. Using plugins and external libraries
This chapter covers
- Using plugins to check code style
- Using plugins to restart the application
- Alternatives to creating the uber jar by hand
- The build project
- Using external libraries in your build
- Adding user-level plugins
- Adding local credentials
One of the advantages of using Scala in general and sbt in particular is that you can easily reuse existing libraries from both the Scala and Java ecosystems. In this chapter we’ll look at how you can reuse existing libraries from within your build code, both indirectly, using sbt plugins, and directly, using the Apache Velocity templating library.
Those who have an Apache Maven, Gradle, or Apache Ant background will be well versed in the idea of plugins (with Ant, they’re called tasks). sbt plugins are similar conceptually to a Maven or Gradle plugin or a Ant task; they’re code that’s executed directly in your build.
For basic usage, sbt is pretty similar. We’ll look at including a plugin—Scalastyle—in your build. Scalastyle checks code for style issues and certain common bugs. You’ll integrate it into your build by using the existing Scalastyle sbt plugin, and then you’ll generate an HTML report of the problems raised by Scalastyle from the results of the scalastyle task.