maven-checkstyle-plugin执行报错:无法识别Lambda表达式出现unexpected token
问题描述
使用mvn checkstyle:check命令对应用做代码规范检查,所用插件版本为maven-checkstyle-plugin:3.1.1,执行时抛出如下错误:
Failed during checkstyle configuration: Exception was thrown while processing .../SomeClass.java: IllegalStateException occurred while parsing file .../SomeClass.java. .../SomeClass.java:35:28: unexpected token: sa ->
报错指向代码中的简单Lambda表达式,对应代码如下:
someStream.map(sa -> { // 报错行指向此处的sa -> // 映射逻辑 return amount; }) .reduce(Amount.ZERO_AMOUNT, MonetaryAmount::add);
原本认为该插件应当支持Java 8语法,也未排查到配置错误,生效pom中的插件配置片段如下:
<plugin> <artifactId>maven-checkstyle-plugin</artifactId> <version>3.1.1</version> <executions> <execution> <id>checkstyle</id> <phase>test</phase> <goals> <goal>check</goal> </goals> <configuration> <configLocation>checkstyle.xml</configLocation> <encoding>UTF-8</encoding> <consoleOutput>true</consoleOutput> <failsOnError>true</failsOnError> <linkXRef>false</linkXRef> </configuration> </execution> </executions> <configuration> <configLocation>checkstyle.xml</configLocation> <encoding>UTF-8</encoding> <consoleOutput>true</consoleOutput> <failsOnError>true</failsOnError> <linkXRef>false</linkXRef> </configuration> </plugin>
请问遗漏了什么配置?
已验证解决方案
目前已确认可行的解决方法为调整checkstyle依赖库的版本:
maven-checkstyle-plugin:3.1.1默认内置的checkstyle版本为8.29,将checkstyle版本升级到9.1- 同步使用最新版Google Java Style规范配置
- 同时将插件版本升级到3.1.2
操作完成后问题解决。
待补充疑问:2020年第一季度发布的8.29版本为何无法支持Lambda表达式,欢迎了解相关机制的朋友补充说明。
内容的提问来源于stack exchange,提问作者h43ckm43ck
相关产品推荐
相关产品推荐

