Maven 指定JDK版本

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>king.test.springmvc</groupId>
    <artifactId>spring-mvc-java-config</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>SpringMvcJavaConfig</name>
    <description>...</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <encoding>UTF-8</encoding>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

使用 IntelliJ 时,一运行 maven build,项目的编译 jdk 总是会变成 1.5 版本,一开始通过maven-compiler-plugin配置指定都不生效,后来在 <properties> 中指定了<maven.compiler.source>1.8</maven.compiler.source> 和 <maven.compiler.target>1.8</maven.compiler.target> 才解决,还未探得终极原因。。。

赞赏


微信赞赏

支付宝赞赏