2

How do I set up my IntelliJ IDEA environment up for JDK8 development? I'm running IntelliJ IDEA 2017.1.3 Community Edition.

There are miscellaneous settings for the Java set up throughout the IDE and from time to time I find all the hiding places and get it set up. I need to occasionally switch between JDK6 and JDK8 development, so it's not quite as simple as reinstall and pick JDK8 for everything. I need to find all the switches in the IDE so I can switch between the two (and show others how to do it) setups reliably.

Please help me find all the settings and correct values to have a positive JDK6 and JDK8 experience

Project Settings

  • IntelliJ IDEA > Preferences > Java Compiler > Project bytecode version
    • 1.8
  • IntelliJ IDEA > Preferences > Java Compiler > Target bytecode version
    • 1.5 for all listed modules
  • File > Project Structure > Project > Project SDK
    • 1.8
  • File > Project Structure > Project > Project language level
    • 5.0 'enum' keyword, generics, autoboxing etc.
  • File > Project Structure > Modules > my project's modules
    • Language Level = 5.0 'enum' keyword, generics, autoboxing etc.

Settings for Creating new projects

  • File > Other Settings > Default Settings > Build, Execution, Deployment > Compiler > Java Compiler > Project bytecode version
    • 1.8
  • File > Other Settings > Default Project Structure > Project > Project SDK
    • No SDK
  • File > Other Settings > Default Project Structure > Project > Project language level
    • 6 - @Override in interfaces
  • File > Other Settings > Default Project Structure > Platform Settings > SDKs
    • confirm 1.6 and 1.8 exist

Solution:

I went through and set all of my "Project Settings" as listed above to JDK8 equivalents. In addition, I ran into a defect in pre 2017.2 version of IDEA IntelliJ which sets target versions to 1.5 unexpectedly. https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000347524-Java-Compiler-target-bytecode-version-Keeps-reverting-to-1-5

According to the post I need to make some hacks to my maven pom.

<properties> <!-- necessary for intellij to function --> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>

MedicineMan
  • 15,008
  • 32
  • 101
  • 146
  • 1
    Go to project settings and add both your JDK's. Then select the one you need for each project. If you use maven, the correct JDK is chosen based on the compiler plugin settings. – Thorbjørn Ravn Andersen Oct 12 '17 at 20:32
  • The three "Default project structure" configures the defaults for when you create a new projects. Unless you create a lot of projects, you can just ignore those... – Per Huss Oct 12 '17 at 20:41
  • @perhuss, in general, the policy is that we don't check in intelliJ project files into git. Wouldn't I be using "Defaults" every time I pull down a new repo and create my local intellij settings? – MedicineMan Oct 12 '17 at 20:46
  • @MedicineMan Yes. Unless you are using a build tool such as maven or gradle for building your project. In that case you will import the project from the pom.xml or build.gradle file and have the project configured automatically within IntelliJ as specified by the build file... – Per Huss Oct 12 '17 at 20:51
  • For us, maven. Ah so this plugin: maven-compiler-plugin, is set to 1.8, so IntelliJ figures out some of the things to do. – MedicineMan Oct 12 '17 at 20:58
  • Make sure your pom.xml specifies both `source` and `target` version to 1.8. – Per Huss Oct 12 '17 at 21:13
  • source and target are 1.8, confirmed. – MedicineMan Oct 12 '17 at 21:16
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/156598/discussion-between-per-huss-and-medicineman). – Per Huss Oct 12 '17 at 21:19
  • @MedicineMan Can you please remove the solution from the question and post it as an answer? Answers don't belong in the question area. – Modus Tollens Oct 12 '17 at 21:51
  • 1
    @MedicineMan it's not a defect, but the documented and expected Maven behavior, see http://stackoverflow.com/a/12900859/104891. – CrazyCoder Oct 14 '17 at 14:32

1 Answers1

1

Under File/Project structure under the Project section each project has its JDK configured by a dropdown. Select the one you want to use and you should be done.

The same section have a project language level, which you probably want to make sure it is "SDK default" which means if you pick java 8 as the project SDK, you will also get to use java 8 features such as lambdas.

The available JDKs are configured globally (one-time operation). I usually add one for each major java version, and edit it when I upgrade to a later update.

Unless you have modules within your project that uses different java versions, you can leave the module settings to defaults.

Hope this helps.

Per Huss
  • 4,755
  • 12
  • 29
  • each repo has a different JDK. I'm seeing more JDK8 work, but there is still the occasional urgent issue in JDK6. A smooth experience is highly desirable. – MedicineMan Oct 12 '17 at 20:50
  • It's ridiculous that there are 5 different settings for a Java 8 experience here. – MedicineMan Oct 12 '17 at 20:52
  • You have been doing something wrong, this really shouldn't be a painful switch... Let's hope we can figure out what and fix it! – Per Huss Oct 12 '17 at 21:15
  • I went to the "Project Settings" above that I've identified and set everything to 8. The syntax error highlighter stopped complaining...DAMN. What is "javacTask: source release 1.8 requires target release 1.8" – MedicineMan Oct 12 '17 at 21:21
  • That means you still have target specified to 1.5... I've started a chat with you, can you see it? – Per Huss Oct 12 '17 at 21:23
  • StackOverflow has chat now? – MedicineMan Oct 12 '17 at 21:24