Basically, I want to check my application with the goal mvn checkstyle:check. The version of the plugin is maven-checkstyle-plugin:3.1.1. However, executing the goal I get the following error message.
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 ->
The unexpected token is actually a simple Lambda expression.
someStream.map(sa -> { // This line here contains the unexpected token: sa -> ???
// some mapping
return amount;
})
.reduce(Amount.ZERO_AMOUNT, MonetaryAmount::add);
I can't imagine that the plugin is not able to interpret java 8 syntax, but I can't find any further evidence of a wrong configuration.
Snippet from the effective 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>
What have I missed?
[UPDATE]
The solution is to adjust the version of the checkstyle library. If you look at the default version defined insight the plugin, it is set to 8.29. I have set the plugin accordingly, as described in Upgrading Checkstyle at Runtime, to the latest version, which is 9.1. I have also defined the latest checkstyle configuration for 'Google Java Style' and the latest plugin version 3.1.2.
Why the plugin did not work with version 8.29 is still a mystery to me. The mentioned version was released in the first quarter of 2020 and lambda expressions should not be a problem.