I am working on a Java library that is can be used both as a generic Java library and as an Android library. I want to avoid using java.nio.file.* classes because they were introduced in the Android platform just recently with API 26, while my Android library targets API 21 and later.
How can I ensure via static code analysis that java.nio.file.* are not used in my Java code? Is there a static code analysis tool that has such feature? I want to integrate it in the build (Maven) and fail any pull requests introducing usage of such classes.
EDIT: Some additional info based on the first answers.
I still want to use Java 7/8 features so setting the source level to 1.6 is not an acceptable approach.
The generic Java library lives in a separate git repository and is imported as a git submodule to the git repository of the Android library. So setting the compileSdkVersion in Android to API 21 won't work.