Maven modifies the default jdk13 version information to solve the problem of too low JDK version

Keywords: Maven JDK xml encoding

The default jdk of Maven is version 1.5. It is too cumbersome to modify the jdk version again every time you create a new project, so the following methods can modify the default jdk version of Maven.

Note: it's better to update Maven's version. The setting.xml jdk13 configuration is invalid when I use version 3.6.3.

1, Add the following code under pom.xml file under the project file (jdk1.8 as an example)

  • pom.xml file content of the current project
<?xml version="1.0" encoding="UTF-8"?>
<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>org.webrx</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <build>
        <finalName>${project.artifactId}</finalName>
        <testSourceDirectory>src/test/java</testSourceDirectory>
        <sourceDirectory>src/main/java</sourceDirectory>
        <!-- Processing failed to load resource profile -->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <!-- Configure the jdk Version information -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>13</source>
                    <target>13</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
  • Configure plugins
<plugins>
            <!-- Configure the jdk Version information -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>13</source>
                    <target>13</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>

2, Set the JDK version of the project created through maven, find the settings.xml file in the downloaded Maven directory, and add the following configuration in the profiles tab

<!-- maven/conf/settins.xml The following configuration is added to the file java Project default use java13 -->
<profiles>
    <profile>
        <id>jdk-13</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>13</jdk>
        </activation>
        <properties>
            <maven.compiler.source>13</maven.compiler.source>
            <maven.compiler.target>13</maven.compiler.target>
            <maven.compiler.compilerVersion>13</maven.compiler.compilerVersion>
        </properties>
    </profile>
</profiles>
Published 1 original article, praised 0, visited 0
Private letter follow

Posted by lynwell07 on Thu, 30 Jan 2020 06:56:20 -0800