views:

43

answers:

2

When I run FindBugs on my project via Maven, I get lots of these:

Can't use annotations when running in JDK 1.4 mode!

How do I fix that? Couldn't find anything in the manual.

A: 

Make sure your Maven build plugin is compiling to 1.5, and not 1.4.

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
Nimlhug
If these options were not set, the build would fail way before the FindBugs plugin is called (so yes, I'm 100% confident that I create Java 5 bytecode).
Aaron Digulla
A: 

I believe you are missing the targetJdk element in the plugin configuration, like in below snippet.

   <reporting>
     <plugins>
       <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>2.0.1</version>
        <configuration>
          <targetJdk>1.5</targetJdk>
        </configuration>
       </plugin>
     </plugins>
   </reporting>
Vineet Reynolds
Unfortunately, this doesn't work. targetJdk is supported for the PMD plugin but not for FindBugs :-(
Aaron Digulla
This actually works but there are a couple of caveats: 1. Specifying the plugin version in a pluginManagement section doesn't work. 2. The option works despite the fact that it's not mentioned anywhere: Not in the docs, not by mvn help:describe ... odd.
Aaron Digulla