I wanted to add a license header to my Scala source code files. It turns out there is a neat sbt plugin called sbt-license-plugin that does just that. Getting it to work took some fiddling around, so I thought I would share it here to save someone else the time and trouble.
When I first added the plugin to my plugin.sbt file under project I got the following exception “sbt.ResolveException: unresolved dependency: com.banno#sbt-license-plugin;0.1.0: not found”. This is caused by a missing resolver as the plugin resides in the Bintray repository hosted by sbt/Typesafe. Anyway, to get the plugin to resolve correctly add the following statements to the project/plugin.sbt file:
resolvers += Resolver.url( "bintray-sbt-plugin-releases", url("http://dl.bintray.com/banno/oss"))( Resolver.ivyStylePatterns) addSbtPlugin("com.banno" % "sbt-license-plugin" % "0.1.0")
Then add the following statements to the beginning of the build.sbt file:
import com.banno.license.Plugin.LicenseKeys._ import com.banno.license.Licenses._ licenseSettings license := apache2("Copyright 2014 nidkil") removeExistingHeaderBlock := true
Now start sbt if you haven’t already and compile
the project. That’s all. Happy coding 🙂