How to change Java version for Maven in IntelliJ?

后端 未结 8 2027
情书的邮戳
情书的邮戳 2020-12-05 01:43

I\'m new to both Maven and IntelliJ IDEA.

I have a Maven project written in Java 8. Whenever I try to build it (Maven Projects window -> Lifecycle -> compile -> Run

相关标签:
8条回答
  • 2020-12-05 02:06

    Adding below lines to root(project level) pom.xml worked me to resolve above issue: (both of the options worked for me)

    Option 1:

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    

    Option 2:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    originally posted at: IntelliJ IDEA 13 uses Java 1.5 despite setting to 1.7

    0 讨论(0)
  • 2020-12-05 02:10

    Change the source as shown below in pom.xml

    <build>
            <finalName>MQService</finalName>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    0 讨论(0)
  • 2020-12-05 02:13

    open the ubuntu terminal goto your root directory and type:

    export JAVA_HOME = <path to jdk>

    for example, it works fine for me {do the same in IntelliJ terminal}.

    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

    to check the set value type echo $JAVA_HOME

    to check the maven version type: mvn -version

    you can find all path of JDKs by typing this command, and you can set JDK version.

    sudo update-alternatives --config java

    also check you have same java -version and javac -version.

    0 讨论(0)
  • 2020-12-05 02:14

    I don't think any response to the question addressed the concern - ". . . in IntelliJ".

    Here are the steps: -

    • Go to Preferences in IntelliJ ( or Shortcut ⌘ + ,)
    • Build, Execution, Deployment > Maven > Importer - select the "JDK for Importer" dropdown then select your preferred java version, Click Apply
    • Build, Execution, Deployment > Maven > Runner - select the "JRE" dropdown then select your preferred java version, Click Apply
    • Click OK
    0 讨论(0)
  • 2020-12-05 02:22

    There are two ways of doing this :

    First- Add Properties

    <properties>
      <maven.compiler.source>1.8</maven.compiler.source>
      <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    

    second- Add Plugin

    <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
    </plugin>
    
    0 讨论(0)
  • 2020-12-05 02:23

    You should add below code in your pom.xml to force the language level to change

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    now intelliJ 2019.3 CE does this for you if you go to import then alt+enter where you will get an option saying "change language level to 8 to use this functionality"

    0 讨论(0)
提交回复
热议问题