问题描述
在IntelliJ IDEA载入Java的checkstyle文件时,报错内容大致如下:
com.puppycrawl.tools.checkstyle.api.CheckstyleException:
cannot initialize module TreeWalker - TreeWalker is not allowed as a parent of LineLength
Please review 'Parent Module' section for this Check in web documentation if Check is standard.
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:473)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:198)
at org.infernus.idea.checkstyle.service.cmd.OpCreateChecker.execute(OpCreateChecker.java:61)
at org.infernus.idea.checkstyle.service.cmd.OpCreateChecker.execute(OpCreateChecker.java:26)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.executeCommand(CheckstyleActionsImpl.java:130)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.createChecker(CheckstyleActionsImpl.java:60)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.createChecker(CheckstyleActionsImpl.java:51)
at org.infernus.idea.checkstyle.checker.CheckerFactoryWorker.run(CheckerFactoryWorker.java:46)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: TreeWalker is not allowed as a parent of LineLength Please review 'Parent Module' section for this Check in web documentation if Check is standard.
at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:147)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:198)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:468)
... 7 more
引发原因
通过查阅资料发现产生问题的原因在于checkstyle的版本更新致使出现不兼容的情况(生气(╯▔皿▔)╯)
解决方法1
手动修改checkstyle版本,经检验本人要载入的文件修改为8.23或8.0后都可成功载入
解决方法2
如果找不到合适的版本,或者懒得找(雾),可以用暴力手段阉割掉出现问题的地方(磨刀霍霍向🐖🐏)
-
打开要载入的xml文件
如图,我这里是用vscode打开的
-
根据报错内容,找出产生错误的module
我直接将报错复制到一个文件里方便查看
阅读后发现问题大致出现在TreeWalker下不能有LineLength模块
斟酌了一下,先尝试注释掉较小的LineLength模块
保存,并再次尝试载入
成功!
后记
这里再分享一个小技巧
在载入时,如果选择的是下图的settings选项,则载入仅对当前项目有效
如果选择下图这样的othersettings,则会默认对所有新创建的项目都有效,就不用每创一次导一次啦~
ps:方法二中被注释掉的内容是否会影响使用还不得而知,如有问题日后会继续补充 : )