maven-compiler-plugin 插件配置详解

最近在本地运行老项目时,将老代码拉下来mvn install发现无法执行。报错如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project ordercenter-facade: Compilation failure
[ERROR] Failure executing javac,  but could not parse the error:
[ERROR] ϵͳ�Ҳ���ָ����·����
[ERROR] 
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

这种非常诡异的报错,让我纠结了好长时间。后来终于发现是因为老项目配置的maven-compiler-plugin插件的一个参数导致的。这里特意记录一下:

该项目maven-compiler-plugin插件中使用了 参数,该参数指定使用的javac命令,而我本地又没有该命令,所以报错了!!!

这里记录一下maven-compiler-plugin常用的配置:

<plugin>                                                                                                                                      
                                                                               
    <groupId>org.apache.maven.pluginsgroupId>                                                                                               
    <artifactId>maven-compiler-pluginartifactId>                                                                                            
    <version>3.1version>                                                                                                                    
    <configuration>                                                                                                                           
                            
        <source>1.8source>                                                                                              
        <target>1.8target>                                                                                      
        <encoding>UTF-8encoding>
        <skipTests>trueskipTests>                                                                             
        <verbose>trueverbose>
        <showWarnings>trueshowWarnings>                                                                                                               
        <fork>truefork>                                                        
        <executable>executable>           
        <compilerVersion>1.3compilerVersion>                                                                         
        <meminitial>128mmeminitial>                                                                                      
        <maxmem>512mmaxmem>                                                                                              
        <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jarcompilerArgument>               
    configuration>                                                                                                                          
plugin>                

maven的默认编译使用的jdk版本貌似很低,使用maven-compiler-plugin插件可以指定项目源码的jdk版本,编译后的jdk版本,以及编码。

你可能感兴趣的:(Java)