IntelliJ idea Language level and Java compiler version automatic change problem

Source: Internet
Author: User
Overview

After the latest version of IntelliJ idea was upgraded, a lot of errors often occur when you compile or package the MAVEN project, and the wrong hints are basically syntax errors caused by the incorrect JDK version. At first not too much attention, thought is the default configuration has not been modified. So the Java compiler and project in the settings
The language level in the settings is changed to its own version, such as jdk1.7, and the problem is temporarily resolved. However, the next time you compile or package the same problem (it turns out that it happened because of changes to the Pom file). cause Analysis

After being checked, it turns out that the root cause of this problem is that no JDK versions are configured in MAVEN's Pom.xml file. When the JDK version is not configured, the Java compiler and language level will automatically revert to the original default 1.5 version once the Pom file has changed. Solution

Add the Maven-compiler-plugin plug-in to the Pom file and specify the JDK version that JDK uses to solve the problem above. The Maven-compiler-plugin configuration also takes effect on both the Java compiler and language level.
Configuration content is as follows:

<build>
    <plugins>
        <plugin>
            <groupid>org.apache.maven.plugins</groupid >
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </ configuration>
        </plugin>
    </plugins>
</build>

I now use the JDK7, so configure 1.7. If you encounter a similar problem, you can configure the appropriate version number according to the specific JDK version you are using.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.