We are currently using Java Compiler 11 and deploy our main artifacts to Java 11. No problem here.
Unfortunately, a service we use only supports Java 8 so we compile some of them targetting Java 8. No problem here.
Our issue is that developers might reference methods that are not available at runtime in Java 8. E.g. List.of()
, Optional::stream
, etc. javac
version 11 will compile it to Java 8, but an exception will be thrown when executed on JVM version 8.
The later is easy enough to identify with a simple grep statement, but the latter is trickier and involves understanding the code/AST.
I checked the docs for Checkstyle, Spotbugs and PMD with no success. IntelliJ is actually very good at this, but it cannot be integrated into our CI pipeline.
And we got this naive/simplistic grep statement:
grep --recursive --extended-regexp '[ \(](List|Set|Map).of' 'our_project'
We would like to have an accurate way to identify incompatible API.