Last Updated: February 25, 2016
·
862
· eller86

Test PMD rule with class which is out of CLASSPATH

In the real environment, sometimes classes which is imported from target class are out of CLASSPATH. I mean we have to suppose that SimpleJavaTypeNode#getType() returns null.

We can use the maven-compiler-plugin to test with this case. The maven-eclipse-plugin is also helpful if you use Eclipse to edit.

<!-- snippet of pom.xml -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <testExcludes>
            <testExclude>**/example/*NotCompiled.java</testExclude>
        </testExcludes>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.9</version>
    <configuration>
        <sourceExcludes>
            <sourceExclude>**/example/*NotCompiled.java</sourceExclude>
        </sourceExcludes>
    </configuration>
</plugin>

Please use my OSS project as an example.
* https://github.com/eller86/ruleset-for-SLF4J