Perché il Checkstyle cerca di creare un assegno per il mio Listener
-
23-09-2019 - |
Domanda
Ho implementato un Checkstyle Listener. Ha funzionato prima, (credo con un rilascio 5.0 beta), ma ora (con 5.0), checkstyle riesce con il seguente CallStack
Unable to create Checker: cannot initialize module de.xyz.toxicity.TeamcityListener - Unable to instantiate de.xyz.toxicity.TeamcityListener
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module de.xyz.toxicity.TeamcityListener - Unable to instantiate de.xyz.toxicity.TeamcityListener
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:177)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:207)
at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:138)
at com.puppycrawl.tools.checkstyle.Main.main(Main.java:115)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate de.xyz.toxicity.TeamcityListener
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:156)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:152)
... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate de.xyz.toxicity.TeamcityListenerCheck
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObjectFactory.java:99)
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:153)
... 4 more
Il mio file di configurazione simile a questo
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="severity" value="warning"/>
<module name="de.xyz.toxicity.TeamcityListener" />
<module name="FileLength">
<property name="max" value="500"/>
</module>
<module name="TreeWalker">
<module name="FileContentsHolder"/>
<module name="AnonInnerLength">
<property name="max" value="35"/>
</module>
// ... more modules like this follow
</module>
</module>
Tutto funziona bene quando il mio Listener viene rimosso dal config.
Ciò che veramente mi confonde è: Perché è checkstyle alla ricerca per la classe TeamcityListenerCheck? una tale classe non esiste. Ho bisogno di esso? Che dovrebbe assomigliare?
Soluzione
Stupido me ... è stato un semplice problema di percorso di classe.
Altri suggerimenti
Si può dare più informazioni sul problema classpath? Sto avendo lo stesso problema. Quando eseguo Checkstyle in ANT utilizzando sun_checks.xml ... nessun problema. Quando aggiungo il mio custom_check.xml ottengo gli stessi messaggi di errore che vedete. Quando si dice Classpath vuoi dire classpath ambiente come% CLASSPATH% o vuoi dire l'impostazione nel file ANT classpath?
Il mio file ANT è impostato in questo modo:
<taskdef resource="checkstyletask.properties">
<classpath>
<pathelement location="\bin"/>
<pathelement location="\lib"/>
<!--<pathelement location="C:ant\lib\myCSCode.jar"/> -->
<pathelement location="C:\checkstyle-5.5\checkstyle-5.5-all.jar"/>
</classpath>
</taskdef>