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>

                            

                 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值