How to find Java version of project


I am working on a plugin that doesn't work well with projects if java version of project is less than 8. How can I determine the java version that is being used for a project? AFAIK its different from the project sdk set in project structure, i.e, I can still clone and open a project written in java 7 and set the project sdk to java 17 - but my plugin won't work in this case. 

So, any suggestion on how can I check java version used in a project from a plugin? 

1 comment


You can check the language level configured for a module:

It can be done with:

LanguageLevelModuleExtension extension = ModuleRootManager.getInstance(module).getModuleExtension(LanguageLevelModuleExtension.class);
boolean isJava8OrHigher = extension.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_8);

Or for file:

PsiJavaFile javaFile = ...;
boolean isJava8OrHigher = javaFile.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_8);

If you meant checking the current file's possible lowest language level, then there is no API to check it. 


Please sign in to leave a comment.