Apache Maven Compiler Plugin 编译器插件

Apache Maven Compiler Plugin

maven是个项目管理工具,如果我们不告诉它我们的代码要使用什么样的jdk版本编译的话,它就会用maven-compiler-plugin默认的jdk版本来进行处理,这样就容易出现版本不匹配,以至于可能导致编译不通过的问题。

maven-compiler-plugin 编译器插件用于编译项目的源代码。 从3.0开始,默认的编译器是javax.tools.JavaCompiler(如果使用的是Java 1.6),并且用于编译Java源代码。 如果要使用javac强制插件,则必须配置插件选项forceJavacCompilerUse。

还要注意,当前,默认的源码设置是1.6,默认的目标设置是1.6,与运行Maven的JDK无关。 强烈建议您按照 Setting the -source and -target of the Java Compiler 中所述,设置source和target来更改这些默认值。

Goals Overview

编译器插件有两个目标。 两者已经绑定到Maven生命周期内的适当阶段,因此将在各自的阶段中自动执行。

Optional Parameters

NameTypeSinceDescription
<annotationProcessorPaths>List3.5

Classpath elements to supply as annotation processor path. If specified, the compiler will detect annotation processors only in those classpath elements. If omitted, the default classpath is used to detect annotation processors. The detection itself depends on the configuration of annotationProcessors.

Each classpath element is specified using their Maven coordinates (groupId, artifactId, version, classifier, type). Transitive dependencies are added automatically. Example:

<configuration>
  <annotationProcessorPaths>
    <path>
      <groupId>org.sample</groupId>
      <artifactId>sample-annotation-processor</artifactId>
      <version>1.2.3</version>
    </path>
    <!-- ... more ... -->
  </annotationProcessorPaths>
</configuration>
<annotationProcessors>String[]2.2

Names of annotation processors to run. Only applies to JDK 1.6+ If not set, the default annotation processors discovery process applies.

<compilerArgs>List3.1

Sets the arguments to be passed to the compiler if fork is set to true. Example:

<compilerArgs>
  <arg>-Xmaxerrs</arg>
  <arg>1000</arg>
  <arg>-Xlint</arg>
  <arg>-J-Duser.language=en_us</arg>
</compilerArgs>
<compilerArgument>String2.0

Sets the unformatted single argument string to be passed to the compiler if fork is set to true. To pass multiple arguments such as -Xmaxerrs 1000 (which are actually two arguments) you have to usecompilerArguments.

This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.

<compilerArguments>Map2.0.1Deprecated. use compilerArgs instead.
<compilerId>String2.0The compiler id of the compiler to use. See this guide for more information.
Default value is: javac.
User property is: maven.compiler.compilerId.
<compilerReuseStrategy>String2.5Strategy to re use javacc class created:
  • reuseCreated (default): will reuse already created but in case of multi-threaded builds, each thread will have its own instance
  • reuseSame: the same Javacc class will be used for each compilation even for multi-threaded build
  • alwaysNew: a new Javacc class will be created for each compilation
Note this parameter value depends on the os/jdk you are using, but the default value should work on most of env.
Default value is: ${reuseCreated}.
User property is: maven.compiler.compilerReuseStrategy.
<compilerVersion>String2.0Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true.
User property is: maven.compiler.compilerVersion.
<debug>boolean2.0Set to true to include debugging information in the compiled class files.
Default value is: true.
User property is: maven.compiler.debug.
<debuglevel>String2.1Keyword list to be appended to the -g command-line switch. Legal values are none or a comma-separated list of the following keywords: lines, vars, and source. If debug level is not specified, by default, nothing will be appended to -g. If debug is not turned on, this attribute will be ignored.
User property is: maven.compiler.debuglevel.
<encoding>String2.1The -encoding argument for the Java compiler.
Default value is: ${project.build.sourceEncoding}.
User property is: encoding.
<excludes>Set2.0A list of exclusion filters for the compiler.
<executable>String2.0Sets the executable of the compiler to use when fork is true.
User property is: maven.compiler.executable.
<failOnError>boolean2.0.2Indicates whether the build will continue even if there are compilation errors.
Default value is: true.
User property is: maven.compiler.failOnError.
<failOnWarning>boolean3.6Indicates whether the build will continue even if there are compilation warnings.
Default value is: false.
User property is: maven.compiler.failOnWarning.
<fileExtensions>List3.1file extensions to check timestamp for incremental build default contains only .class
<forceJavacCompilerUse>boolean3.0compiler can now use javax.tools if available in your current jdk, you can disable this feature using -Dmaven.compiler.forceJavacCompilerUse=true or in the plugin configuration
Default value is: false.
User property is: maven.compiler.forceJavacCompilerUse.
<fork>boolean2.0Allows running the compiler in a separate process. If false it uses the built in compiler, while if true it will use an executable.
Default value is: false.
User property is: maven.compiler.fork.
<generatedSourcesDirectory>File2.2

Specify where to place generated source files created by annotation processing. Only applies to JDK 1.6+


Default value is: ${project.build.directory}/generated-sources/annotations.
<includes>Set2.0A list of inclusion filters for the compiler.
<jdkToolchain>Map3.6

Specify the requirements for this jdk toolchain. This overrules the toolchain selected by the maven-toolchain-plugin.

note: requires at least Maven 3.3.1
<maxmem>String2.0.1Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" if fork is set to true.
User property is: maven.compiler.maxmem.
<meminitial>String2.0.1Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" if fork is set to true.
User property is: maven.compiler.meminitial.
<multiReleaseOutput>boolean3.7.1When set to true, the classes will be placed in META-INF/versions/${release} The release value must be set, otherwise the plugin will fail.
<optimize>boolean2.0Deprecated. This property is a no-op in javac.
Default value is: false.
User property is: maven.compiler.optimize.
<outputFileName>String2.0Sets the name of the output file when compiling a set of sources to a single file. expression="${project.build.finalName}"
<parameters>boolean3.6.2Set to true to generate metadata for reflection on method parameters.
Default value is: false.
User property is: maven.compiler.parameters.
<proc>String2.2

Sets whether annotation processing is performed or not. Only applies to JDK 1.6+ If not set, both compilation and annotation processing are performed at the same time.

Allowed values are:

  • none - no annotation processing is performed.
  • only - only annotation processing is done, no compilation.
<release>String3.6The -release argument for the Java compiler, supported since Java9
User property is: maven.compiler.release.
<showDeprecation>boolean2.0Sets whether to show source locations where deprecated APIs are used.
Default value is: false.
User property is: maven.compiler.showDeprecation.
<showWarnings>boolean2.0Set to true to show compilation warnings.
Default value is: false.
User property is: maven.compiler.showWarnings.
<skipMain>boolean2.0Set this to 'true' to bypass compilation of main sources. Its use is NOT RECOMMENDED, but quite convenient on occasion.
User property is: maven.main.skip.
<skipMultiThreadWarning>boolean2.5(no description)
Default value is: false.
User property is: maven.compiler.skipMultiThreadWarning.
<source>String2.0

The -source argument for the Java compiler.

NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6
Default value is: 1.6.
User property is: maven.compiler.source.
<staleMillis>int2.0Sets the granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
Default value is: 0.
User property is: lastModGranularityMs.
<target>String2.0

The -target argument for the Java compiler.

NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6
Default value is: 1.6.
User property is: maven.compiler.target.
<useIncrementalCompilation>boolean3.1to enable/disable incrementation compilation feature
Default value is: true.
User property is: maven.compiler.useIncrementalCompilation.
<verbose>boolean2.0Set to true to show messages about what the compiler is doing.
Default value is: false.
User property is: maven.compiler.verbose.

 参考http://maven.apache.org/plugins/maven-compiler-plugin/index.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值