In the end how to configure the maven compiler plugin JDK version

Less than a thousand words of official documents, please read the compiler: compile documentation

Configuring maven compiler plugin JDK version

maven compiler plugin (maven-compiler-plugin) has compiled a default JDK version, but this version of the JDK and we usually use the actual development of the inconsistency.

In the compiler: compile a document has two parameter specifies the compiled version of the JDK

The -source argument for the Java compiler.

NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6

  • Type: java.lang.String
  • Since: 2.0
  • Required: No
  • User Property: maven.compiler.source
  • Default: 1.6

......

The -target argument for the Java compiler.

NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6

  • Type: java.lang.String
  • Since: 2.0
  • Required: No
  • User Property: maven.compiler.target
  • Default: 1.6

As mentioned above, the following maven-compiler-plugin3.8.0, the default compiler JDK version is changed to 1.6 from 1.5 a. But it still can not keep up the update rate of the JDK, most systems are currently in use JDK1.8

Note: User PropertyThe instructions below will be used

Can in pom.xmlthis configuration, modify the maven compiler JDK version

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

SpringBoot how to configure JDK version of maven compiler plugin?

In SpringBoot project, we only need the following configuration, you can set the maven compiler plugin JDK version

    <properties>
        <java.version>1.8</java.version>
    </properties>

So, SpringBoot is how to do it?

View spring-boot-starter-parent-2.x.x.RELEASEthe pom file

    <properties>
        ...
        <java.version>1.8</java.version>==
        ...
        <maven.compiler.source>${java.version}</maven.compiler.source>
        ...
        <maven.compiler.target>${java.version}</maven.compiler.target>
    </properties>
    ......
    <build>
         <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <parameters>true</parameters>
                    </configuration>
                </plugin>
             </plugins>
    </build>

It seems, the key point is this <parameters>, is how to see the document says

Set to true to generate metadata for reflection on method parameters.

  • Type: boolean
  • Since: 3.6.2
  • Required: No
  • User Property: maven.compiler.parameters
  • Default: false

English is not good, accurate translation of the meaning does not come out. But the combination of the above evidence, even guess with Mongolia's configuration would be able to know <parameters>what a role.

If you configure the maven compiler plugin <parameters>true</parameters>, then configure the plug-in can be acquired from the user's properties. Each configuration using a specific kind of attribute names in the document parameter User Propertyclear that there.

For example, previously we have to <source>1.8</source>this configuration, version 3.6.2 now use more than maven compiler plugin, you can in the user's properties <maven.compiler.source>1.8</maven.compiler.source>.

SpringBoot is so configured!

How to configure JDK version of maven compiler plugin

If you use SpringBoot, then simply follows in pom.xml

    <properties>
        <java.version>1.8</java.version>
    </properties>

If you do not use SpringBoot, just a simple maven project, as follows (in fact copied SpringBoot practice)

    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
    </properties>

    <build>
         <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <parameters>true</parameters>
                    </configuration>
                </plugin>
             </plugins>
    </build>

Guess you like

Origin www.cnblogs.com/lhat/p/12157124.html