OVO Tech Blog
OVO Tech Blog

Our journey navigating the technosphere

Share


Tags


Awesome SBT plugins for everyone

Without wasting too much of your time on the introduction to the current state of tooling in the Scala ecosystem and how much we all take it for granted these days, I will jump straight to it and give you a quick rundown of some of the awesome and useful plugins for (not so) Simple (Scala) Build Tool, which will make your life easier so you can focus more on developing awesome features for your customers and waste less time messing about with your builds and trying to reinvent the wheel. If you are not a heavy sbt user or you tend to stay away from it as much as possible, hopefully after reading this blog post you will be able to say that sbt can really do cool things and you might even discover one or two plugins you haven’t heard about, which you will find useful enough to adopt on your project and replace some of those old and rusty shell scripts.

CI/CD

Let’s start with plugins which are essential in automating continuous integration and delivery pipelines.
Sbt-release and sbt-native-packager are absolute must-haves which will help you set up a fully automated non-interactive release process for your project. Everything from running tests, cross-building and packaging your application into a Docker image or other native formats, to signing and publishing your artefacts, tagging releases, versioning and pushing any changes back to your repository. Sbt-release allows you to define custom release steps by wrapping other sbt tasks or commands or even by writing your own ad-hoc release steps - the possibilities are almost endless!
If you work on a library, sbt-bintray, sbt-sonatype and sbt-pgp will provide you with an easy way to sign and publish your releases to Bintray and Maven Central repositories.

Code Quality

Other plugins which are quite useful to have in your build process are those related to continuous inspection of code quality.
Sbt-scapegoat, scalastyle and wartremover are great tools for static code analysis (linting) which flag suspicious language usage, identify potential bugs and highlight code which doesn’t adhere to the best practices and Scala style guidelines. Sbt-scoverage will take care of measuring your code coverage so you can track your progress towards getting to that sweet 100%! To automatically upload your scapegoat and scoverage reports to SonarQube you can use sbt-sonar. If you use Coveralls instead, the sbt-coveralls plugin will get you covered - and also for any Codacy users, there is sbt-codacy-coverage plugin.

Dependency Management

Let’s have a look at some plugins which are helpful in managing dependencies in your project.
Sbt-dependency-graph is a go-to tool for digging into dependency graphs and finding out which libraries might have introduced those transitive dependencies, which are suddenly breaking your build or causing some runtime errors. Believe me, there is no better way to spend your Friday than traversing those dependency graphs! For those who feel that the dependency resolution in sbt could be improved upon, coursier with features such as parallel resolution of artifacts, better caching of snapshot dependencies and no global ivy lock is a perfect fit. If you find it difficult to keep track of the latest releases of the libraries that you use, the sbt-updates plugin will make it super easy for you to know when a new version was released and it’s time to update your project to "the latest and greatest". For teams with a strong aversion to particular dependencies or simply those who like to "defend their builds from bad deps" sbt-blockade will get the job done just fine. The last plugin in this category can be quite useful for keeping track of the licences of all of the dependencies in your project - just in case the latest version of one of the libraries introduces a new, less permissive, licence which might have some impact on your project. Or perhaps you want to automatically generate a report and send it to your legal department so they can stay on top of the legal game? If so, then you should have a look at sbt-license-report.

Development

Finally, it’s time to talk a little bit about some of the plugins which are useful during development.
If you find that code reviews in your team are focused too much around code style and formatting, sbt-scalariform and neo-sbt-scalafmt will definitely help you in solving that problem by auto-formatting the source code based on a set of defined rules. You can set up those plugins to be run either in your build pipeline or locally during development, so the code that gets checked into your repository is always beautifully formatted. To generate a class diagram of your project or if you are looking for a visual reassurance that in cats Bimonad mixes in both Monad and Comonad which extends CoflatMap which is a Functor 😉, then sbt-class-diagram is the right tool for the job. If you like keeping track of how big your project is and how fast it is growing, sbt-stats is a nice little plugin which can give you all the numbers - file count, byte size, line count of code, comments and number of characters - how can you not love a plugin like that? Scala-clippy and sbt-errors-summary are great plugins to enrich Scala compiler errors providing you with additional advice and easier to find line numbers and references to the documentation in a nicely formatted and colourful way.

For serialisation and schema evolution, whether it is Avro (sbt-avrohugger, sbt-avro4s), Protobuf (sbt-scalabuff) or Thrift (scrooge), sbt also has your back. There is also something in the store for those invested into GraphQL - sbt-graphql can automatically generate and validate your Sangria schemas. If you need to manage your database migrations with sbt, the plugins that can help you with that are flyway-sbt and sbt-liquibase.

For those who prefer to do as much work as possible within sbt shell or find it disturbing having to constantly juggle multiple terminal windows, here are a few plugins that might help in staying productive. Sbt-sh brings shell support to sbt, sbt-git and sbt-groll make it easier to work with git, sbt-docker along with sbt-docker-compose give you docker integration right within your sbt shell and sbt-prompt with a nicely customised shell prompt will make sure that you think twice before you type in exit and hit enter! And if you are often bored while waiting for your long builds to complete, sbt-youtube can help fill that time pleasantly by playing your favourite YouTube videos!

Testing & Documentation

Finally moving onto the last but not least category of awesome sbt plugins - testing and documentation.
If you have been suffering from flaky tests in your project, don’t wait until they fail the next time, sbt-flaky might just be the plugin which can help you fix your tests today. For benchmarking your code with Java Microbenchmark Harnes there is sbt-jmh and for performance and load testing with Gatling - gatling-sbt.
To make sure your project docs are always up to date regardless of whether you use swagger (sbt-swagger-codegen), raml (sbt-raml-plugin), a simple markdown documentation using sbt-microsites with Scala code type-checked by tut, there are plugins out there to use, so you can hook them up to your build process and automatically ship your docs along with the code and provide always up-to-date documentation for your users.

Wrap up

The magical world of sbt plugins is enormously big and has something to offer for everyone. If you are looking to automate your build process, take a better care of your dependencies, streamline your development experience or even improve your testing and documentation, I am confident that there is an sbt plugin which can do what you are looking for.
I have barely scratched the surface with this list of awesome sbt plugins, so don’t be afraid to explore Github on your own and browse through the rich collection of over 3 thousand plugins. If, for some reason, you still can't find the perfect plugin for the job - don’t be scared - have a go at writing your own and share it with the community. I am 100% sure that sooner or later someone will say to you "that’s awesome, thanks for making my life easier!".

I would also like to take this opportunity and say massive thanks to the whole community and all of the developers out there working really hard on sbt and community plugins, so we all can have an easier job building our Scala projects. 👍🏻👍🏻👍🏻

View Comments