Home > Mobile >  Where should I set version of java in IntelliJ IDEA?
Where should I set version of java in IntelliJ IDEA?

Time:03-05

What is the difference between setting java language version in IntelliJ IDEA in

  1. File -> project Structure -> Project
  2. Run -> Edit configuration -> Build and run
  3. setting java.version, maven.compiler.source, maven.compiler.target in pom.xml

CodePudding user response:

1. File -> project Structure -> Project

This affects only how the IDE compiles your project, but may be overridden when you reload pom.xml, or indeed if you share the project with someone else, that other person will not necesarrily use these settings. Also, if someone were to compile using maven from the commandline, it wouldn't be what you set here.

2. Run -> Edit configuration -> Build and run

This affects only the exceution of your project within the IDE. Thus, even if you have compiled on Java 11, you could test whether it works fine on Java 17 simply by modifying this setting. You could also test with builds by different vendors (e.g. AdoptOpenJDK vs Zulu), should your project require it.

3. setting java.version, maven.compiler.source, maven.compiler.target in pom.xml

I would regard this as the recommended place to set these as opposed to 1, because anyone getting hold of your source code will be able to compile using the same correct language settings, regardless of the IDE or if they use the shell. IDEs will import these and set their local workspace settings (1) accordingly. IntelliJ IDEA will also use the project level setting as the default for new run configurations (2).

  • Related