Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FindBugs with Play Framework 2

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.

like image 352
mpolden Avatar asked Oct 06 '22 15:10

mpolden


1 Answers

I just did this yesterday and documented it in Integrating Findbugs Into a Play Framework 2 Project (Java).

This are the relevant steps:

  1. 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")
    
  2. 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>
  )
)
like image 61
MartinGrotzke Avatar answered Oct 10 '22 03:10

MartinGrotzke