开发者

maven 3 + pmd fails when code has annotations and generics

When I run mvn pmd:pmd I get an warning / error from PMD saying that the code cannot use generics, annotations or Enums with java 1.4 or 1.5. This is supposed to be a error when the targetJdk property is not set (which I did set).

Here is an example of the error I get

[WARNING] Error while parsing /Users/augusto/Downloads/PMD-Clover2-Cobertura-Maven2-Test/PMDTest/src/main/java/org/xh/studies/quality/App.java: Can't use generics unless running in JDK 1.5 mode!

and here's a snippet of the pom I'm using (there's a link to the whole app below)

<build>
   <plugins>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <version>2.3.2</version>
           <configuration>
               <source>1.6</source>
               <target>1.6</target>
           </configuration>
       </plugin>
   </plugins>
</build>

<reporting>
   <plugins>
       <plugin>
           &l开发者_StackOverflowt;groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-pmd-plugin</artifactId>
           <version>2.5</version>
           <configuration>
               <targetJdk>1.6</targetJdk>
           </configuration>
       </plugin>
   </plugins>
</reporting>

I'm using Maven 3.0.2 on mac, with the latest java patch 1.6.0_24.

Click here to download the full project (8kb)


EDIT (26/03/2014)

Since version 3.3 of the maven site plugin, maven can also use the old style configuration (and in fact the maven 2 style is now recommended). Links: docs, jira.


Original answer

Pain, the answer is that the site generation changed completely from maven 2 to maven 3. There is an explanation on this blog. Note that mvn pmd:pmd doesn't work anyway with the new reporting configuration, but it works as part of the site generation.

And here's an example of a pom that works.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.0-beta-2</version>
            <configuration>
                <reportPlugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-project-info-reports-plugin</artifactId>
                        <version>2.3.1</version>
                        <configuration>
                            <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
                            <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>javancss-maven-plugin</artifactId>
                        <version>2.0</version>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>jdepend-maven-plugin</artifactId>
                        <version>2.0-beta-2</version>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-pmd-plugin</artifactId>
                        <version>2.5</version>
                        <configuration>
                            <linkXRef>false</linkXRef>
                            <sourceEncoding>utf-8</sourceEncoding>
                            <minimumTokens>100</minimumTokens>
                            <targetJdk>${java-version}</targetJdk>
                            <verbose>true</verbose>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>findbugs-maven-plugin</artifactId>
                        <version>2.3.2</version>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>2.6</version>
                    </plugin>

                </reportPlugins>
            </configuration>
        </plugin>
    </plugins>
</build>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜