springboot maven-compiler-plugin使用


springboot maven-compiler-plugin使用

                           

官网:Apache Maven Compiler Plugin – Introduction

                         

                         

********************

maven compiler plugin

                             

The Compiler Plugin is used to compile the sources of your project. 
# compiler创建用来编译项目源码

Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) 
and is used to compile Java sources. 
# 从3.0版本开始,maven默认使用javax.tools.JavaCompiler编译项目

If you want to force the plugin using javac, you must configure the plugin option
forceJavacCompilerUse.
# 如果要使用jdk提供的javac进行编译,可以用参数forceJavacCompilerUse

Also note that at present the default source setting is 1.6 and the default target setting 
is 1.6, independently of the JDK you run Maven with
# 编译项目source、target都是1.6版本,和运行maven时使用的jdk版本无关

                         

compiler goal

# compiler:compile 
is bound to the compile phase and is used to compile the main source files
# 和compile阶段绑定,用来编译main source文件

# compiler:testCompile 
is bound to the test-compile phase and is used to compile the test source files
# 和test-compile绑定,用来编译test source文件

                            

相关命令

mvn compile:编译main source文件
mvn test-compile:编译test source文件

                    

                                   

********************

插件配置

****************                 

指定编译版本

                            

设置source、target

    <build>
        <finalName>hello</finalName>
        <plugins>

            ...

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

 实际运行时不一定会使用指定的版本,可指定对应版本的javac路径,fork设置为true

                   

****************   

使用javac编译

                    

    <build>
        <finalName>hello</finalName>
        <plugins>

            ...

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <verbose>true</verbose>

                    <!-- 强制使用javac编译 -->
                    <forceJavacCompilerUse>true</forceJavacCompilerUse>

                    <!-- javac的执行路径 -->
                    <executable>${java.home}\bin\javac</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>

                       

****************   

设置编译内存

                    

    <build>
        <finalName>hello</finalName>
        <plugins>

            ...

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <verbose>true</verbose>
                    <source>16</source>
                    <target>16</target>
                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
                    <executable>${java.home}\bin\javac</executable>

                    <!--初始内存、最大内存-->
                    <meminitial>100m</meminitial>
                    <maxmem>200m</maxmem>
                </configuration>
            </plugin>
        </plugins>
    </build>

                              

****************   

设置编译参数

                    

    <build>
        <finalName>hello</finalName>
        <plugins>

            ...

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>16</source>
                    <target>16</target>
                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
                    <executable>${java.home}\bin\javac</executable>
                    <meminitial>100m</meminitial>
                    <maxmem>200m</maxmem>

                    <!-- 设置编译参数 -->
                    <compilerArgs>
                        <arg>-verbose</arg>
                        <arg>-Xlint:all,-options,-path</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

                            

                 

猜你喜欢

转载自blog.csdn.net/weixin_43931625/article/details/120587829