Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven compiles java projects in jdk 1.4 mode while running java 1.7?

Tags:

java

maven

pmd

I have a big maven project divided to some modules.

I decided to give the pmd (code quality check) module with maven.

when I try to test the pmd module using the command

mvn pmd:pmd

I get the following types of warnings:

  • Can't use generics unless running in JDK 1.5 mode!
  • Can't use annotations when running in JDK 1.4 mode!
  • Can't use enum as a keyword in pre-JDK 1.5 target

looks like maven compiles the projects using jdk 1.4 for some reason.

java -version output:

java version "1.7.0_05"
OpenJDK Runtime Environment (IcedTea7 2.2.1) (Gentoo build 1.7.0_05-b21)
OpenJDK 64-Bit Server VM (build 23.0-b21, mixed mode)

I use gentoo linux.

Linux ufk-work 3.5.2-gentoo #1 SMP Sun Aug 19 18:58:32 IDT 2012 x86_64 Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz GenuineIntel GNU/Linux

mvn -version output:

Apache Maven 3.0.4 (r1232337; 2012-01-17 10:44:56+0200)
Maven home: /usr/share/maven-bin-3.0
Java version: 1.7.0_05, vendor: Oracle Corporation
Java home: /usr/lib64/icedtea7/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.5.2-gentoo", arch: "amd64", family: "unix"

so any ideas how to make sure that maven will compile for jdk 1.7 and not 1.4 ?

I googled and found usage examples of the maven-compiler-plugin as found in the following url: http://twit88.com/blog/2008/03/09/maven-compile-your-application-to-be-14-15-or-16-compatible/

unfortunately the results are exactly the same.

any information regarding the issue would be greatly appreciated.

thank you so much!

kfir

update

I tried adding the maven-compiler-plugin and the maven-pmd-plugin to my main pom.xml but the results are exactly the same.

the updated pom.xml can view at http://bpaste.net/show/41166/

like image 946
ufk Avatar asked Feb 19 '23 11:02

ufk


1 Answers

What you need is to tell the target version of PMD:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-pmd-plugin</artifactId>
      <version>2.7.1</version>
      <configuration>
          <targetJdk>1.7</targetJdk>
          <rulesets>
              <ruleset>tools/pmd-rules.xml</ruleset>
          </rulesets>
      </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5.1</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>

    </plugins>
  </pluginManagement>
</build>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>2.7.1</version>
        </plugin>
    </plugins>
</reporting>

Note: A few month ago the 1.7 JDK was not supported, you should double check it in the documentation, otherwise you won't be able to use the diamond syntax.

like image 111
poussma Avatar answered Feb 28 '23 17:02

poussma