10 Jul 2007, 9:49pm
Projects:
by Cliffano Subagio

11 comments
  • Going Java 1.5 With Maven2-Based Project

    I recently made some simple updates to Wish by using Java 1.5 generics and autoboxing/unboxing. Making Java source changes was the easy part, while the time consuming part was on hunting for information on Maven-related changes.

    I started by changing maven-compiler-plugin source and target in pom.xml:

    <build>
      <plugins>
        ...
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.5</source>
            <target>1.5</target>
          </configuration>
        </plugin>
        ...
      </plugins>
    </build>
    

    And got this error upon running mvn site

    Caused by: net.sourceforge.pmd.ast.ParseException: Can't use generics unless running in JDK 1.5 mode!
    

    which led me to change maven-pmd-plugin targetJdk:

    <reporting>
      <plugins>
        ...
        <plugin>
          <artifactId>maven-pmd-plugin</artifactId>
          <configuration>
            <targetJdk>1.5</targetJdk>
          </configuration>
        </plugin>
        ...
      </plugins>
    </reporting>
    

    Then I found out that the angle brackets used by generics syntax resulted in checkstyle errors:

    <' is not preceded with whitespace.
    error	<;' is not followed by whitespace.
    error	'>' is not preceded with whitespace.
    

    which is fixed by adding these modules to checkstyle.xml .

    If you don’t already have any existing checkstyle rules, create checkstyle.xml file and place it on the root directory of the project (i.e. same place as pom.xml) and add configLocation to maven-checkstyle-plugin:

    <reporting>
      <plugins>
        ...
        <plugin>
          <artifactId>maven-checkstyle-plugin</artifactId>
          <configuration>
            <configLocation>checkstyle.xml</configLocation>
          </configuration>
        </plugin>
        ...
      </plugins>
    </reporting>
    

     

    Recent Posts

    Recent Comments

    • Chess Strategizer: This just got bookmarked! “That’s why I always think of Simon Bolivar and remember that...
    • David from getcheaptrainfares.co.uk: Thank you very much for sharing your wonderful tips! That would definitely be a...
    • Natasha: The quote “Find the best in everybody. Just keep waiting no matter how long it takes. No one is all...
    • Alfonzo Donkin: Stumbled upon your website via bing the other day and absolutely think its great. Carry on the great...
    • Cliffano Subagio: Sure thing.

    Most Commented Posts

    Linkroll