Checkstyle not getting compiled classes on classpath in 1.0 milestone 6


(David Resnick) #1

Since upgrading from M3 to M6 I have started getting these warnings when running checkstyle with the ‘code-quality’ plugin:

Unable to get class information for <custom exception in the same package>

I get this as part of the RedundantThrowsCheck. It seems that the problem has to do with the classpath given to checkstyle. The RedundantThrowsCheck itself includes the note that “The classpath should be configured to locate the class information. The classpath configuration is dependent on the mechanism used to invoke Checkstyle.”

The problem seems to be that I need to include the compiled classes to the checkstyle classpath. This seems to sum up the solution: http://sourceforge.net/tracker/index.php?func=detail&aid=1656084&group_id=29721&atid=397078

How can I put the compiled classes in the checkstyle classpath?

Thanks, David


(Steven Ford) #2

David,

I am having the same issue, have you been able to resolve this?


(David Resnick) #3

I believe that the only fix required was this change in my checkstyle.xml:

<module name="RedundantThrows">
       <property name="allowUnchecked" value="true"/>
       <property name="allowSubclasses" value="true"/>
+
    <property name="suppressLoadErrors" value="true"/>
     </module>
  • David

(Steven Ford) #4

Thanks, that worked. It would be nice if it worked correctly and didn’t require a supression.


(Peter Niederwieser) #5

Please let us know if the new Checkstyle plugin that will ship with m8 solves the problem.


(David Resnick) #6

Right, after posting I realized that suppression of the error is not exactly a fix.


(Luke Daley) #7

Does the checkstyle task require the compiled classes of the source it is analyzing?


(David Resnick) #8

Yes, for some checks it does.


(Steven Ford) #9

Not always. I am in the process of converting our projects to gradle. Any project that uses an Exception that is defined in that project fails on the RedundantThrows check.


(Matt Mastracci) #10

The solution to this for anyone seeing RedundantThrows errors:

checkstyleMain {
  classpath += configurations.compile
 }
 checkstyleTest {
  classpath += configurations.compile
 }

You can’t change the checkstyle classpath from checkstyle {}, but modifying it per-task works.