[FB-Discuss] How to build FindBugs plugin with Maven

Kengo TODA skypencil at gmail.com
Tue Sep 4 00:22:28 EDT 2012


I'm trying to build a FindBugs plugin with Maven, and I found that I cannot put
findbugs.xml into src/main/resources because ExceptionInInitializerError will be
thrown at `test` phase. Its stacktrace is:

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.113
sec <<< FAILURE!
testNopIsNotBug(jp.skypencil.findbugs.simple.OriginalDetectorTest)
Time elapsed: 0.072 sec  <<< ERROR!
java.lang.ExceptionInInitializerError
	at edu.umd.cs.findbugs.DetectorFactoryCollection.getCoreResource(DetectorFactoryCollection.java:360)
	at edu.umd.cs.findbugs.SystemProperties.loadPropertiesFromConfigFile(SystemProperties.java:72)
	at edu.umd.cs.findbugs.SystemProperties.<clinit>(SystemProperties.java:55)
	at edu.umd.cs.findbugs.visitclass.AnnotationVisitor.<clinit>(AnnotationVisitor.java:64)
	at jp.skypencil.findbugs.simple.OriginalDetectorTest.testNopIsNotBug(OriginalDetectorTest.java:14)
        ... (omitted)
Caused by: java.lang.IllegalStateException: Unable to load core plugin
	at edu.umd.cs.findbugs.PluginLoader.loadCorePlugin(PluginLoader.java:1423)
	at edu.umd.cs.findbugs.PluginLoader.loadInitialPlugins(PluginLoader.java:1373)
	at edu.umd.cs.findbugs.PluginLoader.<clinit>(PluginLoader.java:156)
	... 34 more
Caused by: edu.umd.cs.findbugs.PluginDoesntContainMetadataException:
Core pluginfindbugs-2.0.1.jar doesn't contain findbugs.xml; got
file:/D:/cygwin/home/kengo/github/simple-findbugs-plugin/bug-pattern/target/classes/findbugs.xml
from sun.misc.Launcher$AppClassLoader[file:/D:/cygwin/home/kengo/github/simple-findbugs-plugin/bug-pattern/target/surefire/surefirebooter4183093093081081854.jar]
	at edu.umd.cs.findbugs.PluginLoader.getPluginDescriptor(PluginLoader.java:1112)
	at edu.umd.cs.findbugs.PluginLoader.init(PluginLoader.java:611)
	at edu.umd.cs.findbugs.PluginLoader.<init>(PluginLoader.java:357)
	at edu.umd.cs.findbugs.PluginLoader.loadCorePlugin(PluginLoader.java:1419)
	... 36 more


I know that the reason is findbugs loads
src/main/resources/findbugs.xml instead of
findbugs.xml in own jar. But I have 2 reasons to put my XML in
src/main/resources:

  1. to package my XML into my original jar
  2. to test my plugin with @ExpectWarning and others

Would you suggest me to resolve this problem? Currently I use <profile> to
avoid the 1st problem, but I think this workaround is evil.
https://gist.github.com/3616511

I uploaded a simple Maven project to reproduce this exception. I hope
it helps you.
http://github.com/eller86/simple-findbugs-plugin


Thanks in advance.

-- 
***
Kengo TODA (eller86)
skypencil at gmail.com
http://skypencil.jp/


More information about the Findbugs-discuss mailing list