3

When I open a workspace in Eclipse Oxygen, the default compiler compliance level is set to 9. I change it in Preferences > Java > Compiler back to 1.8 and click Apply. It works, until I close Eclipse and reopen it and now it's back to 9. How can I make the change stick?

Note: I know that /instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.compliance is set somewhere to 9, but I can't find out where that is.

Shant Dashjian
  • 888
  • 11
  • 20
  • Why not set it at project level? – ernest_k May 02 '18 at 04:28
  • 2
    Changing `Preference` is supposed to remember values between restarts of Eclipse. If that doesn't happen, perhaps Eclipse has trouble saving the workspace settings. Where did you create the workspace? Hopefully not inside `Program Files` or `ProgramData` on Windows, because that's generally protected by UAC. – Andreas May 02 '18 at 05:20
  • @Andreas I'm using a Mac, and I created my workspace in my home directory. – Shant Dashjian May 02 '18 at 06:12
  • @ErnestKiwele I want Eclipse to remember my setting for the entire workspace. I do appreciate the workaround though. – Shant Dashjian May 02 '18 at 06:15
  • 1
    I can reproduce the problem using Oxygen.2 but neither in Oxygen.3a, nor recent milestones towards Photon. Which exact release are you using? – Stephan Herrmann May 03 '18 at 13:17
  • 1
    Like Stephan, I am also unable to reproduce this problem using Oxygen.3a Release (4.7.3a), so if you are on an earlier version simply upgrading may solve your problem (if that is an available option). – skomisa May 03 '18 at 16:37
  • I am using Oxygen.3a, and it simply doesn't remember me setting the compiler compliance level to 1.8. It reverts back to 9 after I close and reopen Eclipse. I do have both Java 9 in addition to Java 8 on my Mac. Do you have Java 9 installed on your machine? – Shant Dashjian May 04 '18 at 01:01
  • @ShaunDashjian I have JDKs 8, 9 and 10 installed (and in **Preferences > Java > Installed JREs** I have set JDK 10 as the default JRE). Everything works fine for me. – skomisa May 04 '18 at 03:15
  • 1
    @ShaunDashjian Perhaps you could create a new workspace and create a couple of dummy projects, and see if the compliance problem persists in with the new workspace. If compliance works with that new workspace (i.e. your setting persists over restarts) then you will have isolated your problem to one specific workspace. Worth a try since it will only take a couple of minutes... – skomisa May 04 '18 at 03:18
  • @skomisa just tried that to no avail. Same behavior with new workspace. – Shant Dashjian May 04 '18 at 03:43
  • @ShaunDashjian OK. One more thing that is simple to try is to change compliance for a specific project (using **{project} > Properties > Java Compiler > JDK Compliance**) and see if that persists over a restart of Eclipse. – skomisa May 04 '18 at 04:01
  • @skomisa Yes, project level compliance persists, but not the workspace level compliance. – Shant Dashjian May 04 '18 at 04:23
  • I wonder if it has to do with the fact that I have both Java 9 and Java 8 installed. I will try to remove Java 9 all together and see that fixes the problem. – Shant Dashjian May 04 '18 at 04:28
  • @ShaunDashjian Another approach is to start Eclipse with the **-clean** parameter to see if that helps. I doubt it, but since it's easy to try it's worth a go. This [article on **-clean**](https://www.eclipsezone.com/eclipse/forums/t61566.html) is very old, but I think it is still valid. – skomisa May 05 '18 at 05:18

2 Answers2

1

I cannot replicate your problem of compliance changes not persisting across restarts, but you can manually set them rather than using Eclipse's GUI. To do that:

  • Close Eclipse.
  • Locate your preferences file. This is a text file containing many of settings you normally assign in Eclipse using Window > Preferences. The file will be in your workspace directory within the .metadata directory with the following name:

    .metadata.plugins\org.eclipse.core.runtime.settings\org.eclipse.jdt.core.prefs

  • Open the file org.eclipse.jdt.core.prefs in a text editor and edit the following three lines:

org.eclipse.jdt.core.compiler.codegen.targetPlatform=9

org.eclipse.jdt.core.compiler.compliance=9

org.eclipse.jdt.core.compiler.source=9

  • Replace the three instances of "9" with "1.8" for JDK 1.8 compliance (or "10" for JDK 10 compliance). Those three properties correspond to the three fields you see on the Compiler screen which specify a version, as shown below.
  • Restart Eclipse and go to Preferences > Java > Compiler. The settings for the compiler should now all be set to 1.8:

complianceGUI

This approach worked for me. However, even if this approach solves your problem, you could still raise a Bug Report with Eclipse since it should not be necessary to manually edit the preferences file.

skomisa
  • 16,436
  • 7
  • 61
  • 102
  • That did not work on my machine. I will raise a bug report with Eclipse. – Shant Dashjian May 06 '18 at 18:17
  • 1
    What exactly "did not work"? Presumably you were able to edit **org.eclipse.jdt.core.prefs**, so is the situation that after editing the that file and starting Eclipse you still see the old/default settings with compliance level=9? And if so, do your changes to org.eclipse.jdt.core.prefs also get removed? If so it certainly seems like a bug report is appropriate. – skomisa May 06 '18 at 18:34
  • I edit the file to 1.8, but when I open Eclipse, the file content and the UI both revert back to 9. That file is clearly being overwritten by Eclipse when it starts. – Shant Dashjian May 06 '18 at 20:19
  • 1
    Is it possible that you are using Oomph on startup (perhaps unknowingly), and that is why your changes to **org.eclipse.jdt.core.prefs** are being automatically regressed? See [my answer](https://stackoverflow.com/questions/48094584/eclipse-java-templates-reset-on-restart/48427485#48427485) to the SO post **Eclipse Java templates reset on restart** for more information. The end of that answer explains how to determine whether Oomph is being used on startup. – skomisa May 06 '18 at 21:43
  • Darn it! That was it. It was always getting the settings from `~/.eclipse/org.eclipse.oomph.setup/setups/user.setup`, over-writting whatever is in the workspace. – Shant Dashjian May 07 '18 at 02:31
1

My workspace settings were getting over-written by user-specific settings stored in ~/.eclipse/org.eclipse.oomph.setup/setups/user.setup. Specifically, that file included those leftover setup lines from a previous installation:

<setupTask
      xsi:type="setup:PreferenceTask"
      key="/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.codegen.targetPlatform"
      value="9"/>
  <setupTask
      xsi:type="setup:PreferenceTask"
      key="/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.compliance"
      value="9"/>
  <setupTask
      xsi:type="setup:PreferenceTask"
      key="/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.source"
      value="9"/>
</setupTask>

Solution: Remove the lines above from ~/.eclipse/org.eclipse.oomph.setup/setups/user.setup.

Note: Thanks to @skomisa who helped me figure this out.

Shant Dashjian
  • 888
  • 11
  • 20