I'd like to integrate FindBugs into the build process of a Play Framework 2 Java project.
Is this possible? If so, what are the configuration steps required to make it work?
I'm assuming it's possible to use findbugs4sbt, but I'm unsure about how to set it up.
I just did this yesterday and documented it in Integrating Findbugs Into a Play Framework 2 Project (Java).
This are the relevant steps:
Download my custom build of findbugs4sbt jar for sbt 0.11 from bitbucket and put it into project/lib
Update: Add the plugin in project/plugins.sbt
via
addSbtPlugin("de.johoop" % "findbugs4sbt" % "1.1.7")
Configure findbugs4sbt in project/Build.scala
:
import de.johoop.findbugs4sbt.FindBugs._
object ApplicationBuild extends Build {
...
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA,
settings = Defaults.defaultSettings ++ findbugsSettings)
}
Then you can already run sbt findbugs
which generates target/scala-2.9.1/findbugs/findbugs.xml
.
As findbugs also analyzes some classes compiled by play from routes and views (and reports some issues regarding naming conventions), you probably want to ignore them (as you can't improve them anyways). To do this exclude them from findbugs with the following findbugs4sbt settings (in project/Build.scala
):
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA,
settings = Defaults.defaultSettings ++ findbugsSettings).settings(
findbugsExcludeFilters := Some(
<FindBugsFilter>
<!-- See docs/examples at http://findbugs.sourceforge.net/manual/filter.html -->
<Match>
<Class name="~views\.html\..*"/>
</Match>
<Match>
<Class name="~Routes.*"/>
</Match>
<Match>
<Class name="~controllers\.routes.*"/>
</Match>
</FindBugsFilter>
)
)
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