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>

    Related Posts:

    21 Aug 2007, 7:12pm
    by Vikas Hazrati

    reply

    Very useful tip. Thanks

    Very useful.. if I could make it to work !

    I probably missed somthing. I have a specific checkstyle file and I put the new modules this way inside the treewalker module :

    <module name=”NoWhitespaceAfter”>
    <!– Default tokens and additional GENERIC_START –>
    <property name=”tokens” value=”ARRAY_INIT, BNOT, DEC, DOT, INC, LNOT,
    UNARY_MINUS, UNARY_PLUS, GENERIC_START”/>
    </module>

    <module name=”NoWhitespaceBefore”>
    <!– Default tokens and additional GENERIC_START and GENERIC_END –>
    <property name=”tokens” value=”SEMI, POST_DEC, POST_INC,
    GENERIC_START, GENERIC_END”/>
    </module>

    <module name=”WhitespaceAfter”>
    <!– Default tokens and additional GENERIC_END –>
    <property name=”tokens” value=”COMMA, SEMI, TYPECAST, GENERIC_END”/>
    </module>

    <module name=”WhitespaceAround”>
    <!– Default tokens without GENERIC_START and GENERIC_END –>
    <property name=”tokens” value=”ASSIGN, BAND, BAND_ASSIGN, BOR,
    BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV,
    DIV_ASSIGN, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT,
    LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
    LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SYNCHRONIZED,
    LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD,
    MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL,
    SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN,
    TYPE_EXTENSION_AND, WILDCARD_TYPE”/>
    </module>

    It continues reporting errors for missing spaces before and after < and > in generics. Any idea about what I am doing wrong ?

    14 Sep 2007, 7:02pm
    by Grateful Visitor

    reply

    Man, thanks a bunch :) You saved my backside!

    Thanks for the tip – saved me a lot of trouble. Tip for pys: remove the existing NoWhitespaceAfter, NoWhitespaceBefore, WhitespaceAfter and WhitespaceAround modules from your checkstyle file. They probably override the new settings that you added. It should work after you do that.

    Thanks, it just be very useful for me.

    Thanks … works really well for me.

    8 Jul 2008, 6:52pm
    by børrild

    reply

    Tip for phn and pys: The genric-tokens are not valid token parameters for the checks “NoWhitespaceAfter”, “NoWhitespaceBefore” and “WhitespaceAfter”, they are simply ignored.

    I’m having trouble with the

    Any ideas if it is related to the nowhistespaceafter modules? I’ve tried changing the code around a bit but nothing is changing yet.

    29 Mar 2009, 1:51am
    by Martinez Marchand

    reply

    Weird, it didn’t show the code. I’m having issues with the whitespacearound module. The whole block of code just gives me some messed up error.

    I am getting this error when using ‘jspc-maven-plugin’ I run maven Install.

    C:/WorkSpace/msp-operations/build/WEB-INF/jsp/user/assignClients.jsp(2,0) File “/msp.tld” not found

    The path for msp.tld is specified in the web.xml file which i am not able to refer.

    thus can u please help me how to refer this .

    Got rid of the annoying build warnings for PMD. Thanks!

    *name

    *e-mail

    web site

    leave a comment


     

    Recent Posts

    Recent Comments

    • Tharindu: i started blogging long long time back but couldnt continue. last november i stated blogging again with...
    • maria: maybe he didnt believe in god, i dont either and does it really matter?? his message is the same:he talks...
    • Cliffano Subagio: Sure thing. The license for the images is Creative Commons Attribution Share Alike...
    • daniel: nice articles. can I copy your images? :D
    • Cliffano Subagio: Only an idea, won’t be made into real site (unless someone else wants to do it). Something...

    Most Commented Posts

    Linkroll