Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode Maven error `The compiler compliance specified is 1.7 but a JRE 13 is used`

I created a new maven project in VSCode. When I try to run a file, I get this error

The compiler compliance specified is 1.7 but a JRE 13 is used

but there are no instructions on how to fix the error. What do I do?

These are the VSC plugins I have installed:

  • Debugger for Java 0.25.0
  • Java Dependency Viewer 0.9.0
  • Java Extension Pack 0.8.1
  • Java Run 1.1.4
  • Java Test Runner 0.22.0
like image 424
Cody Avatar asked Mar 02 '20 23:03

Cody


2 Answers

To solve this problem, you have to update manually the pom.xml file. Everything you have to do is explained in the doc, section "Java 9 or later". Here are the steps to follow.

The default pom.xml file provide theses informations:

Old version - pom.xml

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.8.0</version>
          </plugin>
        </plugins>
    </pluginManagement>
</build>

As you can see, Maven uses an outdated plugin to be used with maven.compiler.source for Java 1.7. Here you want to update the plugin an specify the use of Java 13. Modify pom.xml like so:

New solution version - pom.xml

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.release>13</maven.compiler.release>
</properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Now don't forget to update VSCode configutation by right-clicking on the pom.xml file then click on Update Project Configuration or do Alt+Shift+U and wait for the change to apply.

Normally, the PROBLEMS section should be No problems have been detected in the workspace so far.

like image 179
Onyr Avatar answered Nov 17 '22 16:11

Onyr


my problem was similar but with JDK11 and JDK14

In my case, I changed the version in the pom.xml, like @Onyr said, but the problem kept popping up. To fix it I followed these steps:

  1. In VSCode, press Crtl + Shift + P. This will show a popup when you can write
  2. Then write >Configure Java runtime (Make sure not to delete the character >)
  3. Click the first result to open the configure window
  4. In my case, I saw this:

enter image description here

As you can see, the current path point to JDK14, but I want to use JDK11

  1. So, click in User Setting (Blue link in "Type" column)
  2. Then, click in Edit in settings.json
  3. Now, you have to searh a property called "java.home" and change the path to the JDK you want to use

For example, in my case, this line changed from:

"java.home": "C:\\Program Files\\Java\\jdk-14.0.2",

To:

"java.home": "C:\\Program Files\\Java\\jdk-11.0.8",
  1. Finally, VSCode will show a popup asking you to restart the config. Do it and the problem go
like image 35
Daniel Alvarez Avatar answered Nov 17 '22 15:11

Daniel Alvarez