compiler:compile

Full name:

org.apache.maven.plugins:maven-compiler-plugin:4.0.0-beta-3:compile

Description:

Compiles application sources. Each instance shall be used only once, then discarded.
See also: javac Command

Attributes:

  • Requires a Maven project to be executed.
  • The goal is not marked as thread-safe and thus does not support parallel builds.
  • Since version: 2.0.
  • Binds by default to the lifecycle phase: compile.

Optional Parameters

Name Type Since Description
<annotationProcessorPaths> List<DependencyCoordinate> 3.5
Deprecated.
Replaced by ordinary dependencies with <type> element set to processor, classpath-processor or modular-processor.

Classpath elements to supply as annotation processor path. If specified, the compiler will detect annotation processors only in those classpath elements. If omitted (and proc is set to only or full), the default classpath is used to detect annotation processors. The detection itself depends on the configuration of annotationProcessors. Since JDK 23 by default no annotation processing is performed as long as no processors is listed for security reasons. Therefore, you should always list the desired processors using this configuration element or annotationProcessorPaths.

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

<configuration>
  <annotationProcessorPaths>
    <path>
      <groupId>org.sample</groupId>
      <artifactId>sample-annotation-processor</artifactId>
      <version>1.2.3</version> <!-- Optional - taken from dependency management if not specified -->
      <!-- Optionally exclude transitive dependencies -->
      <exclusions>
        <exclusion>
          <groupId>org.sample</groupId>
          <artifactId>sample-dependency</artifactId>
        </exclusion>
      </exclusions>
    </path>
    <!-- ... more ... -->
  </annotationProcessorPaths>
</configuration>
Note: Exclusions are supported from version 3.11.0.
See also: javac -processorpath, javac Annotation Processing
<annotationProcessorPathsUseDepMgmt> boolean 3.12.0
Deprecated.
This flag is ignored. Replaced by ordinary dependencies with <type> element set to processor, classpath-processor or modular-processor.

Whether to use the Maven dependency management section when resolving transitive dependencies of annotation processor paths.

This flag does not enable / disable the ability to resolve the version of annotation processor paths from dependency management section. It only influences the resolution of transitive dependencies of those top-level paths.

<annotationProcessors> String[] 2.2 Class names of annotation processors to run. If not set, the default annotation processors discovery process applies. If set, the value will be appended to the -processor compiler option.
See also: proc
<compileSourceRoots> List<String> -
Deprecated.
Replaced by the project-wide <sources> element.

The root directories containing the source files to be compiled. If null or empty, the directories will be obtained from the <Source> elements declared in the project. If non-empty, the project <Source> elements are ignored. This configuration option should be used only when there is a need to override the project configuration.
<compilerArgs> List<String> 3.1 Additional arguments to be passed verbatim to the Java compiler. This parameter can be used when the Maven compiler plugin does not provide a parameter for a Java compiler option. It may happen, for example, for new or preview Java features which are not yet handled by this compiler plugin.

If an option has a value, the option and the value shall be specified in two separated <arg> elements. For example, the -Xmaxerrs 1000 option (for setting the maximal number of errors to 1000) can be specified as below (together with other options):

<compilerArgs>
  <arg>-Xlint</arg>
  <arg>-Xmaxerrs</arg>
  <arg>1000</arg>
  <arg>J-Duser.language=en_us</arg>
</compilerArgs>
Note that -J options should be specified only if fork is set to true. Other options can be specified regardless the fork value. The compiler plugin does not verify whether the arguments given through this parameter are valid. For this reason, the other parameters provided by the compiler plugin should be preferred when they exist, because the plugin checks whether the corresponding options are supported.
See also: javac -J
<compilerArgument> String -
Deprecated.
Use compilerArgs instead.

The single argument string to be passed to the compiler. To pass multiple arguments such as -Xmaxerrs 1000 (which are actually two arguments), compilerArgs is preferred.

Note that -J options should be specified only if fork is set to true.


See also: javac -J
<compilerId> String - Identifier of the compiler to use. This identifier shall match the identifier of a compiler known to the JDK tool chain, or the JavaCompiler#name() name of a javax.tools.JavaCompiler instance registered as a service findable by java.util.ServiceLoader. See this guide for more information. If unspecified, then the system Java compiler is used. The identifier of the system Java compiler is usually javac.
See also: fork, executable, JavaCompiler#name()
<compilerReuseStrategy> String 2.5
Deprecated.
Not supported anymore. The reuse of javax.tools.JavaFileManager instance is plugin implementation details.

Strategy to re use javacc class created. Legal values are:
  • 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.
<compilerVersion> String -
Deprecated.
This parameter is no longer used by the underlying compilers.

Version of the compiler to use if fork is set to true. Examples! "1.3", "1.5".
See also: fork
<createMissingPackageInfoClass> boolean 3.10 Whether to generate package-info.class even when empty. By default, package info source files that only contain javadoc and no annotation on the package can lead to no class file being generated by the compiler. It may cause a file miss on build systems that check for file existence in order to decide what to recompile.

If true, the -Xpkginfo:always compiler option is added if the compiler supports that extra option. If the extra option is not supported, then a warning is logged and no option is added to the compiler arguments.


See also: incrementalCompilation
<debug> boolean -
Deprecated.
Setting this flag to false is replaced by <debuglevel>none</debuglevel>.

Whether to include debugging information in the compiled class files. The amount of debugging information to include is specified by the debuglevel parameter. If this debug flag is true, then the -g option may be added to compiler arguments with a value determined by the debuglevel argument. If this debug flag is false, then the -g:none option will be added to the compiler arguments.
See also: debuglevel, javac -g
<debugFileName> String 3.10.0 The file where to dump the command-line when debug is activated or when the compilation failed. For example, if the value is "javac", then the Java compiler can be launched from the command-line by typing javac @target/javac.args. The debug file will contain the compiler options together with the list of source files to compile.

By default, this debug file is written only if the compilation of main code failed. The writing of the debug files can be forced by setting the verbose flag to true or by specifying the --verbose option to Maven on the command-line.

<debuglevel> String 2.1 Kinds of debugging information to include in the compiled class files. Legal values are lines, vars, source, all and none. Values other than all and none can be combined in a comma-separated list.

If debug level is not specified, then the -g option will not be added, which means that the default debugging information will be generated (typically lines and source but not vars).

If debug level is all, then only the -g option is added, which means that all debugging information will be generated. If debug level is anything else, then the comma-separated list of keywords is appended to the -g command-line switch.


See also: javac -g:[lines,vars,source]
<enablePreview> boolean 3.10.1 Whether to enable preview language features of the java compiler. If true, then the --enable-preview option will be added to compiler arguments.
See also: javac --enable-preview
<encoding> String 2.1 The -encoding argument for the Java compiler.
See also: javac -encoding
<excludes> Set<String> - A set of exclusion filters for the compiler.
<executable> String - Executable of the compiler to use when fork is true. If this parameter is specified, then the jdkToolchain is ignored.
See also: jdkToolchain, fork, compilerId
<failOnError> boolean 2.0.2 Whether the build will stop if there are compilation errors.
See also: failOnWarning
<failOnWarning> boolean 3.6 Whether the build will stop if there are compilation warnings. If true, then the -Werror option will be added to compiler arguments.
See also: showWarnings, showDeprecation
<fileExtensions> List<String> 3.1 File extensions to check timestamp for incremental build. Default contains only class and jar. TODO: Rename with a name making clearer that this parameter is about incremental build.
See also: incrementalCompilation
<forceJavacCompilerUse> Boolean 3.0
Deprecated.
Ignored because java.lang.Compiler has been deprecated and removed from the JDK.

Whether to use legacy compiler API.
<forceLegacyJavacApi> Boolean 3.13
Deprecated.
Ignored because the compiler plugin now always use the javax.tools API.

Whether to use the legacy com.sun.tools.javac API instead of javax.tools API.
See also: New API, Legacy API
<fork> boolean - Allows running the compiler in a separate process. If false, the plugin uses the built-in compiler, while if true it will use an executable.
See also: executable, compilerId, meminitial, maxmem
<generatedSourcesDirectory> Path 2.2 Specify where to place generated source files created by annotation processing.
<implicit> String 3.10.2 Whether to generate class files for implicitly referenced files. If set, the value will be appended to the -implicit: compiler option. Standard values are:
  • class – automatically generates class files.
  • none – suppresses class file generation.

See also: javac -implicit
<includes> Set<String> - A set of inclusion filters for the compiler.
<incrementalCompilation> String 4.0.0 The algorithm to use for selecting which files to compile. Values can be dependencies, sources, classes, rebuild-on-change, rebuild-on-add, modules or none.

options: recompile all source files if the compiler options changed. Changes are detected on a best-effort basis only.

dependencies: recompile all source files if at least one dependency (JAR file) changed since the last build. This check is based on the last modification times of JAR files.

sources: recompile source files modified since the last build. In addition, if a source file has been deleted, then all source files are recompiled. This check is based on the modification times of source files rather than the modification times of the *.class files.

classes: recompile source files (*.java) associated to no output file (*.class) or associated to an output file older than the source. This algorithm does not check if a source file has been removed, potentially leaving non-recompiled classes with references to classes that no longer exist.

The sources and classes values are partially redundant, doing the same work in different ways. It is usually not necessary to specify those two values.

modules: recompile modules and let the compiler decides which individual files to recompile. The compiler plugin does not enumerate the source files to recompile (actually, it does not scan at all the source directories). Instead, it only specifies the module to recompile using the --module option. The Java compiler will scan the source directories itself and compile only those source files that are newer than the corresponding files in the output directory.

rebuild-on-add: modifier for recompiling all source files when the addition of a new file is detected. This flag is effective only when used together with sources or classes. When used with classes, it provides a way to detect class renaming (this is not needed with sources for detecting renaming).

rebuild-on-change: modifier for recompiling all source files when a change is detected in at least one source file. This flag is effective only when used together with sources or classes. It does not rebuild when a new source file is added without change in other files, unless rebuild-on-add is also specified.

none: the compiler plugin unconditionally specifies all sources to the Java compiler. This option is mutually exclusive with all other incremental compilation options.

Limitations

In all cases, the current compiler-plugin does not detect structural changes other than file addition or removal. For example, the plugin does not detect whether a method has been removed in a class.

Default value

The default value depends on the context. If there is no annotation processor, then the default is "options,dependencies,sources". It means that a full rebuild will be done if the compiler options or the dependencies changed, or if a source file has been deleted. Otherwise, only the modified source files will be recompiled.

If an annotation processor is present (e.g., proc set to a value other than "none"), then the default value is same as above with the addition of "rebuild-on-add,rebuild-on-change". It means that a full rebuild will be done if any kind of change is detected.


See also: staleMillis, fileExtensions, showCompilationChanges, createMissingPackageInfoClass
<incrementalExcludes> Set<String> 3.11 A set of exclusion filters for the incremental calculation. Updated source files, if excluded by this filter, will not cause the project to be rebuilt.

Limitation

In the current implementation, those exclusion filters are applied for added or removed files, but not yet for removed files.
<jdkToolchain> Map<String,String> 3.6 Requirements for this JDK toolchain for using a different javac than the one of the JDK used by Maven. This overrules the toolchain selected by the maven-toolchain-plugin. See Guide to Toolchains for more info.
<configuration>
  <jdkToolchain>
    <version>11</version>
  </jdkToolchain>
  ...
</configuration>

<configuration>
  <jdkToolchain>
    <version>1.8</version>
    <vendor>zulu</vendor>
  </jdkToolchain>
  ...
</configuration>

See also: fork, executable
<maxmem> String 2.0.1 Maximum size, in megabytes, of the memory allocation pool if fork is set to true. Examples: "128", "128M". Suffixes "k" (for kilobytes) and "G" (for gigabytes) are also accepted. If no suffix is provided, "M" is assumed.
See also: fork
<meminitial> String 2.0.1 Initial size, in megabytes, of the memory allocation pool if fork is set to true. Examples: "64", "64M". Suffixes "k" (for kilobytes) and "G" (for gigabytes) are also accepted. If no suffix is provided, "M" is assumed.
See also: fork
<moduleVersion> String 4.0.0 The --module-version argument for the Java compiler. This is ignored if not applicable, e.g., in non-modular projects.
See also: javac --module-version
<multiReleaseOutput> boolean 3.7.1
Deprecated.
Replaced by specifying the <targetVersion> value inside a <source> element.

When set to true, the classes will be placed in META-INF/versions/${release}.

Note: A jar is only a multi-release jar if META-INF/MANIFEST.MF contains Multi-Release: true. You need to set this by configuring the maven-jar-plugin. This implies that you cannot test a multi-release jar using the outputDirectory.

<optimize> Boolean -
Deprecated.
This property is ignored.

Whether to optimize the compiled code using the compiler's optimization methods.
<outputFileName> String -
Deprecated.
Bundling many class files into a single file should be done by other plugins.

Sets the name of the output file when compiling a set of sources to a single file.

expression="${project.build.finalName}"

<outputTimestamp> String 3.12.0
Deprecated.
Not used by the compiler plugin since it does not generate archive.

Timestamp for reproducible output archive entries. It can be either formatted as ISO 8601 yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
<parameters> boolean 3.6.2 Whether to generate metadata for reflection on method parameters. If true, the -parameters option will be added to compiler arguments.
See also: javac -parameters
<proc> String 2.2 Configures if annotation processing and/or compilation are performed by the compiler. If set, the value will be appended to the -proc: compiler option. Possible values are:
  • none – no annotation processing is performed, only compilation is done.
  • only – only annotation processing is done, no compilation.
  • full – annotation processing followed by compilation is done.
The default value depends on the JDK used for the build. Prior to Java 23, the default was full, so annotation processing and compilation were executed without explicit configuration. For security reasons, starting with Java 23 no annotation processing is done if neither any -processor, -processor path or -processor module are set, or either only or full is set. So literally the default is none. It is recommended to always list the annotation processors you want to execute instead of using the proc configuration, to ensure that only desired processors are executed and not any "hidden" (and maybe malicious).
See also: annotationProcessors, Inside Java 2024-06-18 Quality Heads up, javac -proc, javac Annotation Processing
<release> String 3.6 The --release argument for the Java compiler when the sources do not declare this version. The suggested way to declare the target Java release is to specify it with the sources like below:
<build>
  <sources>
    <source>
      <directory>src/main/java</directory>
      <targetVersion>17</targetVersion>
    </source>
  </sources>
</build>
If such <targetVersion> element is found, it has precedence over this release property. If a source does not declare a target Java version, then the value of this release property is used as a fallback. If omitted, the compiler will generate bytecodes for the Java version running the compiler.
See also: javac --release
<showCompilationChanges> boolean - Whether to provide more details about why a module is rebuilt. This is used only if incrementalCompilation is set to something else than "none".
See also: incrementalCompilation
<showDeprecation> boolean - Whether to show source locations where deprecated APIs are used. If true, then the -deprecation option will be added to compiler arguments. That option is itself a shorthand for -Xlint:deprecation.
See also: showWarnings, failOnWarning
<showWarnings> boolean - Whether to show compilation warnings. If false, then the -nowarn option will be added to compiler arguments. That option is itself a shorthand for -Xlint:none.
See also: showDeprecation, failOnWarning
<skipMain> boolean - Set this to true to bypass compilation of main sources. Its use is not recommended, but quite convenient on occasion.
<skipMultiThreadWarning> Boolean 2.5
Deprecated.
Deprecated as a consequence of compilerReuseStrategy deprecation.

No description.
<source> String - The --source argument for the Java compiler.

Notes:

  • Since 3.8.0 the default value has changed from 1.5 to 1.6.
  • Since 3.9.0 the default value has changed from 1.6 to 1.7.
  • Since 3.11.0 the default value has changed from 1.7 to 1.8.
  • Since 4.0.0-beta-2 the default value has been removed. As of Java 9, the release parameter is preferred.

See also: javac --source
<staleMillis> int - The granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
See also: incrementalCompilation
<target> String - The --target argument for the Java compiler.

Notes:

  • Since 3.8.0 the default value has changed from 1.5 to 1.6.
  • Since 3.9.0 the default value has changed from 1.6 to 1.7.
  • Since 3.11.0 the default value has changed from 1.7 to 1.8.
  • Since 4.0.0-beta-2 the default value has been removed. As of Java 9, the release parameter is preferred.

See also: javac --target
<useIncrementalCompilation> Boolean 3.1
Deprecated.
Replaced by incrementalCompilation. A value of true in this old property is equivalent to "dependencies,sources,rebuild-on-add" in the new property, and a value of false is equivalent to "classes".

Whether to enable/disable incremental compilation feature.
<verbose> boolean - Whether to show messages about what the compiler is doing. If true, then the -verbose option will be added to compiler arguments. In addition, files such as target/javac.args will be generated even on successful compilation.
See also: javac -verbose

Parameter Details

<annotationProcessorPaths>

Deprecated.
Replaced by ordinary dependencies with <type> element set to processor, classpath-processor or modular-processor.

Classpath elements to supply as annotation processor path. If specified, the compiler will detect annotation processors only in those classpath elements. If omitted (and proc is set to only or full), the default classpath is used to detect annotation processors. The detection itself depends on the configuration of annotationProcessors. Since JDK 23 by default no annotation processing is performed as long as no processors is listed for security reasons. Therefore, you should always list the desired processors using this configuration element or annotationProcessorPaths.

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

<configuration>
  <annotationProcessorPaths>
    <path>
      <groupId>org.sample</groupId>
      <artifactId>sample-annotation-processor</artifactId>
      <version>1.2.3</version> <!-- Optional - taken from dependency management if not specified -->
      <!-- Optionally exclude transitive dependencies -->
      <exclusions>
        <exclusion>
          <groupId>org.sample</groupId>
          <artifactId>sample-dependency</artifactId>
        </exclusion>
      </exclusions>
    </path>
    <!-- ... more ... -->
  </annotationProcessorPaths>
</configuration>
Note: Exclusions are supported from version 3.11.0.
See also: javac -processorpath, javac Annotation Processing

<annotationProcessorPathsUseDepMgmt>

Deprecated.
This flag is ignored. Replaced by ordinary dependencies with <type> element set to processor, classpath-processor or modular-processor.

Whether to use the Maven dependency management section when resolving transitive dependencies of annotation processor paths.

This flag does not enable / disable the ability to resolve the version of annotation processor paths from dependency management section. It only influences the resolution of transitive dependencies of those top-level paths.

  • Type: boolean
  • Since: 3.12.0
  • Required: No

<annotationProcessors>

Class names of annotation processors to run. If not set, the default annotation processors discovery process applies. If set, the value will be appended to the -processor compiler option.
See also: proc
  • Type: java.lang.String[]
  • Since: 2.2
  • Required: No

<compileSourceRoots>

Deprecated.
Replaced by the project-wide <sources> element.

The root directories containing the source files to be compiled. If null or empty, the directories will be obtained from the <Source> elements declared in the project. If non-empty, the project <Source> elements are ignored. This configuration option should be used only when there is a need to override the project configuration.
  • Type: java.util.List<java.lang.String>
  • Required: No

<compilerArgs>

Additional arguments to be passed verbatim to the Java compiler. This parameter can be used when the Maven compiler plugin does not provide a parameter for a Java compiler option. It may happen, for example, for new or preview Java features which are not yet handled by this compiler plugin.

If an option has a value, the option and the value shall be specified in two separated <arg> elements. For example, the -Xmaxerrs 1000 option (for setting the maximal number of errors to 1000) can be specified as below (together with other options):

<compilerArgs>
  <arg>-Xlint</arg>
  <arg>-Xmaxerrs</arg>
  <arg>1000</arg>
  <arg>J-Duser.language=en_us</arg>
</compilerArgs>
Note that -J options should be specified only if fork is set to true. Other options can be specified regardless the fork value. The compiler plugin does not verify whether the arguments given through this parameter are valid. For this reason, the other parameters provided by the compiler plugin should be preferred when they exist, because the plugin checks whether the corresponding options are supported.
See also: javac -J
  • Type: java.util.List<java.lang.String>
  • Since: 3.1
  • Required: No

<compilerArgument>

Deprecated.
Use compilerArgs instead.

The single argument string to be passed to the compiler. To pass multiple arguments such as -Xmaxerrs 1000 (which are actually two arguments), compilerArgs is preferred.

Note that -J options should be specified only if fork is set to true.


See also: javac -J
  • Type: java.lang.String
  • Required: No

<compilerId>

Identifier of the compiler to use. This identifier shall match the identifier of a compiler known to the JDK tool chain, or the JavaCompiler#name() name of a javax.tools.JavaCompiler instance registered as a service findable by java.util.ServiceLoader. See this guide for more information. If unspecified, then the system Java compiler is used. The identifier of the system Java compiler is usually javac.
See also: fork, executable, JavaCompiler#name()
  • Type: java.lang.String
  • Required: No

<compilerReuseStrategy>

Deprecated.
Not supported anymore. The reuse of javax.tools.JavaFileManager instance is plugin implementation details.

Strategy to re use javacc class created. Legal values are:
  • 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.
  • Type: java.lang.String
  • Since: 2.5
  • Required: No

<compilerVersion>

Deprecated.
This parameter is no longer used by the underlying compilers.

Version of the compiler to use if fork is set to true. Examples! "1.3", "1.5".
See also: fork
  • Type: java.lang.String
  • Required: No

<createMissingPackageInfoClass>

Whether to generate package-info.class even when empty. By default, package info source files that only contain javadoc and no annotation on the package can lead to no class file being generated by the compiler. It may cause a file miss on build systems that check for file existence in order to decide what to recompile.

If true, the -Xpkginfo:always compiler option is added if the compiler supports that extra option. If the extra option is not supported, then a warning is logged and no option is added to the compiler arguments.


See also: incrementalCompilation
  • Type: boolean
  • Since: 3.10
  • Required: No

<debug>

Deprecated.
Setting this flag to false is replaced by <debuglevel>none</debuglevel>.

Whether to include debugging information in the compiled class files. The amount of debugging information to include is specified by the debuglevel parameter. If this debug flag is true, then the -g option may be added to compiler arguments with a value determined by the debuglevel argument. If this debug flag is false, then the -g:none option will be added to the compiler arguments.
See also: debuglevel, javac -g
  • Type: boolean
  • Required: No

<debugFileName>

The file where to dump the command-line when debug is activated or when the compilation failed. For example, if the value is "javac", then the Java compiler can be launched from the command-line by typing javac @target/javac.args. The debug file will contain the compiler options together with the list of source files to compile.

By default, this debug file is written only if the compilation of main code failed. The writing of the debug files can be forced by setting the verbose flag to true or by specifying the --verbose option to Maven on the command-line.

  • Type: java.lang.String
  • Since: 3.10.0
  • Required: No

<debuglevel>

Kinds of debugging information to include in the compiled class files. Legal values are lines, vars, source, all and none. Values other than all and none can be combined in a comma-separated list.

If debug level is not specified, then the -g option will not be added, which means that the default debugging information will be generated (typically lines and source but not vars).

If debug level is all, then only the -g option is added, which means that all debugging information will be generated. If debug level is anything else, then the comma-separated list of keywords is appended to the -g command-line switch.


See also: javac -g:[lines,vars,source]
  • Type: java.lang.String
  • Since: 2.1
  • Required: No

<enablePreview>

Whether to enable preview language features of the java compiler. If true, then the --enable-preview option will be added to compiler arguments.
See also: javac --enable-preview
  • Type: boolean
  • Since: 3.10.1
  • Required: No

<encoding>

The -encoding argument for the Java compiler.
See also: javac -encoding
  • Type: java.lang.String
  • Since: 2.1
  • Required: No

<excludes>

A set of exclusion filters for the compiler.
  • Type: java.util.Set<java.lang.String>
  • Required: No

<executable>

Executable of the compiler to use when fork is true. If this parameter is specified, then the jdkToolchain is ignored.
See also: jdkToolchain, fork, compilerId
  • Type: java.lang.String
  • Required: No

<failOnError>

Whether the build will stop if there are compilation errors.
See also: failOnWarning
  • Type: boolean
  • Since: 2.0.2
  • Required: No

<failOnWarning>

Whether the build will stop if there are compilation warnings. If true, then the -Werror option will be added to compiler arguments.
See also: showWarnings, showDeprecation
  • Type: boolean
  • Since: 3.6
  • Required: No

<fileExtensions>

File extensions to check timestamp for incremental build. Default contains only class and jar. TODO: Rename with a name making clearer that this parameter is about incremental build.
See also: incrementalCompilation
  • Type: java.util.List<java.lang.String>
  • Since: 3.1
  • Required: No

<forceJavacCompilerUse>

Deprecated.
Ignored because java.lang.Compiler has been deprecated and removed from the JDK.

Whether to use legacy compiler API.
  • Type: java.lang.Boolean
  • Since: 3.0
  • Required: No

<forceLegacyJavacApi>

Deprecated.
Ignored because the compiler plugin now always use the javax.tools API.

Whether to use the legacy com.sun.tools.javac API instead of javax.tools API.
See also: New API, Legacy API
  • Type: java.lang.Boolean
  • Since: 3.13
  • Required: No

<fork>

Allows running the compiler in a separate process. If false, the plugin uses the built-in compiler, while if true it will use an executable.
See also: executable, compilerId, meminitial, maxmem
  • Type: boolean
  • Required: No

<generatedSourcesDirectory>

Specify where to place generated source files created by annotation processing.
  • Type: java.nio.file.Path
  • Since: 2.2
  • Required: No

<implicit>

Whether to generate class files for implicitly referenced files. If set, the value will be appended to the -implicit: compiler option. Standard values are:
  • class – automatically generates class files.
  • none – suppresses class file generation.

See also: javac -implicit
  • Type: java.lang.String
  • Since: 3.10.2
  • Required: No

<includes>

A set of inclusion filters for the compiler.
  • Type: java.util.Set<java.lang.String>
  • Required: No

<incrementalCompilation>

The algorithm to use for selecting which files to compile. Values can be dependencies, sources, classes, rebuild-on-change, rebuild-on-add, modules or none.

options: recompile all source files if the compiler options changed. Changes are detected on a best-effort basis only.

dependencies: recompile all source files if at least one dependency (JAR file) changed since the last build. This check is based on the last modification times of JAR files.

sources: recompile source files modified since the last build. In addition, if a source file has been deleted, then all source files are recompiled. This check is based on the modification times of source files rather than the modification times of the *.class files.

classes: recompile source files (*.java) associated to no output file (*.class) or associated to an output file older than the source. This algorithm does not check if a source file has been removed, potentially leaving non-recompiled classes with references to classes that no longer exist.

The sources and classes values are partially redundant, doing the same work in different ways. It is usually not necessary to specify those two values.

modules: recompile modules and let the compiler decides which individual files to recompile. The compiler plugin does not enumerate the source files to recompile (actually, it does not scan at all the source directories). Instead, it only specifies the module to recompile using the --module option. The Java compiler will scan the source directories itself and compile only those source files that are newer than the corresponding files in the output directory.

rebuild-on-add: modifier for recompiling all source files when the addition of a new file is detected. This flag is effective only when used together with sources or classes. When used with classes, it provides a way to detect class renaming (this is not needed with sources for detecting renaming).

rebuild-on-change: modifier for recompiling all source files when a change is detected in at least one source file. This flag is effective only when used together with sources or classes. It does not rebuild when a new source file is added without change in other files, unless rebuild-on-add is also specified.

none: the compiler plugin unconditionally specifies all sources to the Java compiler. This option is mutually exclusive with all other incremental compilation options.

Limitations

In all cases, the current compiler-plugin does not detect structural changes other than file addition or removal. For example, the plugin does not detect whether a method has been removed in a class.

Default value

The default value depends on the context. If there is no annotation processor, then the default is "options,dependencies,sources". It means that a full rebuild will be done if the compiler options or the dependencies changed, or if a source file has been deleted. Otherwise, only the modified source files will be recompiled.

If an annotation processor is present (e.g., proc set to a value other than "none"), then the default value is same as above with the addition of "rebuild-on-add,rebuild-on-change". It means that a full rebuild will be done if any kind of change is detected.


See also: staleMillis, fileExtensions, showCompilationChanges, createMissingPackageInfoClass
  • Type: java.lang.String
  • Since: 4.0.0
  • Required: No

<incrementalExcludes>

A set of exclusion filters for the incremental calculation. Updated source files, if excluded by this filter, will not cause the project to be rebuilt.

Limitation

In the current implementation, those exclusion filters are applied for added or removed files, but not yet for removed files.
  • Type: java.util.Set<java.lang.String>
  • Since: 3.11
  • Required: No

<jdkToolchain>

Requirements for this JDK toolchain for using a different javac than the one of the JDK used by Maven. This overrules the toolchain selected by the maven-toolchain-plugin. See Guide to Toolchains for more info.
<configuration>
  <jdkToolchain>
    <version>11</version>
  </jdkToolchain>
  ...
</configuration>

<configuration>
  <jdkToolchain>
    <version>1.8</version>
    <vendor>zulu</vendor>
  </jdkToolchain>
  ...
</configuration>

See also: fork, executable
  • Type: java.util.Map<java.lang.String, java.lang.String>
  • Since: 3.6
  • Required: No

<maxmem>

Maximum size, in megabytes, of the memory allocation pool if fork is set to true. Examples: "128", "128M". Suffixes "k" (for kilobytes) and "G" (for gigabytes) are also accepted. If no suffix is provided, "M" is assumed.
See also: fork
  • Type: java.lang.String
  • Since: 2.0.1
  • Required: No

<meminitial>

Initial size, in megabytes, of the memory allocation pool if fork is set to true. Examples: "64", "64M". Suffixes "k" (for kilobytes) and "G" (for gigabytes) are also accepted. If no suffix is provided, "M" is assumed.
See also: fork
  • Type: java.lang.String
  • Since: 2.0.1
  • Required: No

<moduleVersion>

The --module-version argument for the Java compiler. This is ignored if not applicable, e.g., in non-modular projects.
See also: javac --module-version
  • Type: java.lang.String
  • Since: 4.0.0
  • Required: No

<multiReleaseOutput>

Deprecated.
Replaced by specifying the <targetVersion> value inside a <source> element.

When set to true, the classes will be placed in META-INF/versions/${release}.

Note: A jar is only a multi-release jar if META-INF/MANIFEST.MF contains Multi-Release: true. You need to set this by configuring the maven-jar-plugin. This implies that you cannot test a multi-release jar using the outputDirectory.

  • Type: boolean
  • Since: 3.7.1
  • Required: No

<optimize>

Deprecated.
This property is ignored.

Whether to optimize the compiled code using the compiler's optimization methods.
  • Type: java.lang.Boolean
  • Required: No

<outputFileName>

Deprecated.
Bundling many class files into a single file should be done by other plugins.

Sets the name of the output file when compiling a set of sources to a single file.

expression="${project.build.finalName}"

  • Type: java.lang.String
  • Required: No

<outputTimestamp>

Deprecated.
Not used by the compiler plugin since it does not generate archive.

Timestamp for reproducible output archive entries. It can be either formatted as ISO 8601 yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
  • Type: java.lang.String
  • Since: 3.12.0
  • Required: No

<parameters>

Whether to generate metadata for reflection on method parameters. If true, the -parameters option will be added to compiler arguments.
See also: javac -parameters
  • Type: boolean
  • Since: 3.6.2
  • Required: No

<proc>

Configures if annotation processing and/or compilation are performed by the compiler. If set, the value will be appended to the -proc: compiler option. Possible values are:
  • none – no annotation processing is performed, only compilation is done.
  • only – only annotation processing is done, no compilation.
  • full – annotation processing followed by compilation is done.
The default value depends on the JDK used for the build. Prior to Java 23, the default was full, so annotation processing and compilation were executed without explicit configuration. For security reasons, starting with Java 23 no annotation processing is done if neither any -processor, -processor path or -processor module are set, or either only or full is set. So literally the default is none. It is recommended to always list the annotation processors you want to execute instead of using the proc configuration, to ensure that only desired processors are executed and not any "hidden" (and maybe malicious).
See also: annotationProcessors, Inside Java 2024-06-18 Quality Heads up, javac -proc, javac Annotation Processing
  • Type: java.lang.String
  • Since: 2.2
  • Required: No

<release>

The --release argument for the Java compiler when the sources do not declare this version. The suggested way to declare the target Java release is to specify it with the sources like below:
<build>
  <sources>
    <source>
      <directory>src/main/java</directory>
      <targetVersion>17</targetVersion>
    </source>
  </sources>
</build>
If such <targetVersion> element is found, it has precedence over this release property. If a source does not declare a target Java version, then the value of this release property is used as a fallback. If omitted, the compiler will generate bytecodes for the Java version running the compiler.
See also: javac --release
  • Type: java.lang.String
  • Since: 3.6
  • Required: No

<showCompilationChanges>

Whether to provide more details about why a module is rebuilt. This is used only if incrementalCompilation is set to something else than "none".
See also: incrementalCompilation
  • Type: boolean
  • Required: No

<showDeprecation>

Whether to show source locations where deprecated APIs are used. If true, then the -deprecation option will be added to compiler arguments. That option is itself a shorthand for -Xlint:deprecation.
See also: showWarnings, failOnWarning
  • Type: boolean
  • Required: No

<showWarnings>

Whether to show compilation warnings. If false, then the -nowarn option will be added to compiler arguments. That option is itself a shorthand for -Xlint:none.
See also: showDeprecation, failOnWarning
  • Type: boolean
  • Required: No

<skipMain>

Set this to true to bypass compilation of main sources. Its use is not recommended, but quite convenient on occasion.
  • Type: boolean
  • Required: No

<skipMultiThreadWarning>

Deprecated.
Deprecated as a consequence of compilerReuseStrategy deprecation.

No description.
  • Type: java.lang.Boolean
  • Since: 2.5
  • Required: No

<source>

The --source argument for the Java compiler.

Notes:

  • Since 3.8.0 the default value has changed from 1.5 to 1.6.
  • Since 3.9.0 the default value has changed from 1.6 to 1.7.
  • Since 3.11.0 the default value has changed from 1.7 to 1.8.
  • Since 4.0.0-beta-2 the default value has been removed. As of Java 9, the release parameter is preferred.

See also: javac --source
  • Type: java.lang.String
  • Required: No

<staleMillis>

The granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
See also: incrementalCompilation
  • Type: int
  • Required: No

<target>

The --target argument for the Java compiler.

Notes:

  • Since 3.8.0 the default value has changed from 1.5 to 1.6.
  • Since 3.9.0 the default value has changed from 1.6 to 1.7.
  • Since 3.11.0 the default value has changed from 1.7 to 1.8.
  • Since 4.0.0-beta-2 the default value has been removed. As of Java 9, the release parameter is preferred.

See also: javac --target
  • Type: java.lang.String
  • Required: No

<useIncrementalCompilation>

Deprecated.
Replaced by incrementalCompilation. A value of true in this old property is equivalent to "dependencies,sources,rebuild-on-add" in the new property, and a value of false is equivalent to "classes".

Whether to enable/disable incremental compilation feature.
  • Type: java.lang.Boolean
  • Since: 3.1
  • Required: No

<verbose>

Whether to show messages about what the compiler is doing. If true, then the -verbose option will be added to compiler arguments. In addition, files such as target/javac.args will be generated even on successful compilation.
See also: javac -verbose
  • Type: boolean
  • Required: No