zoukankan      html  css  js  c++  java
  • 12) maven-compiler-plugin

    The Compiler Plugin is used to compile the sources of your project. 

    At present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. 

    Change these defaults:

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
        </plugins>
        [...]
      </build>
      [...]
    </project>

    http://maven.apache.org/components/plugins/maven-compiler-plugin/

    注意事项1:

    除了配置这个插件,如果是在eclipse中,Installed Jres 需要存在1.7 ,不然实际使用的jdk不是1.7 。

    举例说明:eclipse 中只有1.6 和 1.8 

     

    配置成1.7 ,但实际使用的是选中的1.8

    如果存在1.7 ,实际使用的则是1.7(默认的仍然是1.8)

    注意事项2:

    在命令行中执行是使用的环境变量配置的 JAVA_HOME

    测试新建了一个 Maven项目,指定1.8 ,在类中使用1.8特有的 java.util.stream.Stream 

    然后修改环境变量到1.7 , 用命令行执行 mvn compile 显示编译失败

    F:eworkspace_FP_ebiscusz-test2>mvn compile
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building z-test2 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ z-test2 ---
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 0 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ z-test2 ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
    [INFO] Compiling 1 source file to F:eworkspace_FP_ebiscusz-test2	argetclasses
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.141 s
    [INFO] Finished at: 2016-12-19T15:44:02+08:00
    [INFO] Final Memory: 8M/105M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project z-test2: Fatal error compiling: inva
    lid target release: 1.8 -> [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/MojoExecutionException
  • 相关阅读:
    洛谷-P5743 【深基7.习8】猴子吃桃
    洛谷-P5741 【深基7.例10】旗鼓相当的对手
    洛谷-P5740 【深基7.例9】最厉害的学生
    洛谷-P5739 【深基7.例7】计算阶乘
    jvm中常见的指令笔记
    join()方法的源码分析
    Java中线程状态的各种转换关系
    java构造器遇到父类没有无参构造的分析
    jvm栈和堆
    spring新注解
  • 原文地址:https://www.cnblogs.com/zno2/p/4583178.html
Copyright © 2011-2022 走看看