compiler:compile

Full name:

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

Description:

Compiles application sources. By default uses the javac compiler of the JDK used to execute Maven. This can be overwritten through Toolchains or parameter compilerId.
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

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. 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

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

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


See also: javac -processor, javac Annotation Processing
<compilePath> List<String> - No description.
<compileSourceRoots> List<String> - The source directories containing the sources to be compiled.
<compilerArgs> List<String> 3.1

Sets the arguments to be passed to the compiler.

Note that -J options are only passed through 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>

See also: javac -J
<compilerArgument> String -

Sets the unformatted single argument string to be passed to the compiler. To pass multiple arguments such as -Xmaxerrs 1000 (which are actually two arguments) you have to use compilerArgs.

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

Note that -J options are only passed through if fork is set to true.


See also: javac -J
<compilerId> String - The compiler id of the compiler to use. See this guide for more information.
<compilerReuseStrategy> String 2.5 Strategy 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.
<compilerVersion> String -
Deprecated.
This parameter is no longer evaluated by the underlying compilers, instead the actual version of the javac binary is automatically retrieved.

Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true.
<createMissingPackageInfoClass> boolean 3.10 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. This causes a file miss on the next compilations and forces an unnecessary recompilation. The default value of true causes an empty class file to be generated. This behavior can be changed by setting this parameter to false.
<debug> boolean - Set to true to include debugging information in the compiled class files.
See also: javac -g, debuglevel
<debugFileName> String 3.10.0 When both fork and debug are enabled the commandline arguments used will be dumped to this file.
<debuglevel> String 2.1 Keyword 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.
See also: javac -G:[lines,vars,source]
<enablePreview> boolean 3.10.1 Set to true to enable preview language features of the java compiler
See also: javac --enable-preview
<encoding> String 2.1 The -encoding argument for the Java compiler.
See also: javac -encoding
<excludes> Set<String> - A list of exclusion filters for the compiler.
<executable> String - Sets the executable of the compiler to use when fork is true.
<failOnError> boolean 2.0.2 Indicates whether the build will continue even if there are compilation errors.
<failOnWarning> boolean 3.6 Indicates whether the build will continue even if there are compilation warnings.
<fileExtensions> List<String> 3.1 File extensions to check timestamp for incremental build. Default contains only class and jar.
<forceLegacyJavacApi> boolean 3.13 The underlying compiler now uses javax.tools API if available in your current JDK. Set this to true to always use the legacy com.sun.tools.javac API instead.

This only has an effect for compilerId being javac and fork being false.

<fork> boolean - Allows running the compiler in a separate process. If false it uses the built in compiler, while if true it will use an executable.
<generatedSourcesDirectory> Path 2.2

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

<implicit> String 3.10.2 Keyword to be appended to the -implicit: command-line switch.
See also: javac -implicit
<includes> Set<String> - A list of inclusion filters for the compiler.
<incrementalExcludes> Set<String> 3.11 A list of exclusion filters for the incremental calculation.
<jdkToolchain> Map<String,String> 3.6

Specify the requirements for this jdk toolchain for using a different javac than the one of the JRE 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>
note: requires at least Maven 3.3.1
<maxmem> String 2.0.1 Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" if fork is set to true.
<meminitial> String 2.0.1 Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" if fork is set to true.
<mojoStatusPath> String 3.0 needed for storing the status for the incremental build support. No description.
<multiReleaseOutput> boolean 3.7.1

When set to true, the classes will be placed in META-INF/versions/${release} The release value must be set, otherwise the plugin will fail.

Note: A jar is only a multirelease 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 multirelease jar using the outputDirectory.
<optimize> boolean -
Deprecated.
This property is a no-op in javac.

Set to true to optimize the compiled code using the compiler's optimization methods.
<outputFileName> String - 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 Timestamp for reproducible output archive entries, 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 Set to true to generate metadata for reflection on method parameters.
See also: javac -parameters
<proc> String 2.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.
  • full - annotation processing and compilation.
full is the default. Starting with JDK 21, this option must be set explicitly.
See also: javac -proc, javac Annotation Processing
<release> String 3.6 The -release argument for the Java compiler, supported since Java9
See also: javac -release
<showCompilationChanges> boolean - No description.
<showDeprecation> boolean - Sets whether to show source locations where deprecated APIs are used.
<showWarnings> boolean - Set to false to disable warnings during compilation.
<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 No description.
<source> String -

The -source argument for the Java compiler.

NOTE:

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


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

The -target argument for the Java compiler.

NOTE:

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


See also: javac -target
<useIncrementalCompilation> boolean 3.1

to enable/disable incremental compilation feature.

This leads to two different modes depending on the underlying compiler. The default javac compiler does the following:

  • true (default) in this mode the compiler plugin determines whether any JAR files the current module depends on have changed in the current build run; or any source file was added, removed or changed since the last compilation. If this is the case, the compiler plugin recompiles all sources.
  • false (not recommended) this only compiles source files which are newer than their corresponding class files, namely which have changed since the last compilation. This does not recompile other classes which use the changed class, potentially leaving them with references to methods that no longer exist, leading to errors at runtime.
<verbose> boolean - Set to true to show messages about what the compiler is doing.
See also: javac -verbose

Parameter Details

<annotationProcessorPaths>

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. 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>

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>

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


See also: javac -processor, javac Annotation Processing
  • Type: java.lang.String[]
  • Since: 2.2
  • Required: No

<compilePath>

No description.
  • Type: java.util.List<java.lang.String>
  • Required: No

<compileSourceRoots>

The source directories containing the sources to be compiled.
  • Type: java.util.List<java.lang.String>
  • Required: No

<compilerArgs>

Sets the arguments to be passed to the compiler.

Note that -J options are only passed through 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>

See also: javac -J
  • Type: java.util.List<java.lang.String>
  • Since: 3.1
  • Required: No

<compilerArgument>

Sets the unformatted single argument string to be passed to the compiler. To pass multiple arguments such as -Xmaxerrs 1000 (which are actually two arguments) you have to use compilerArgs.

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

Note that -J options are only passed through if fork is set to true.


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

<compilerId>

The compiler id of the compiler to use. See this guide for more information.
  • Type: java.lang.String
  • Required: No

<compilerReuseStrategy>

Strategy 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.
  • Type: java.lang.String
  • Since: 2.5
  • Required: No

<compilerVersion>

Deprecated.
This parameter is no longer evaluated by the underlying compilers, instead the actual version of the javac binary is automatically retrieved.

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

<createMissingPackageInfoClass>

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. This causes a file miss on the next compilations and forces an unnecessary recompilation. The default value of true causes an empty class file to be generated. This behavior can be changed by setting this parameter to false.
  • Type: boolean
  • Since: 3.10
  • Required: No

<debug>

Set to true to include debugging information in the compiled class files.
See also: javac -g, debuglevel
  • Type: boolean
  • Required: No

<debugFileName>

When both fork and debug are enabled the commandline arguments used will be dumped to this file.
  • Type: java.lang.String
  • Since: 3.10.0
  • Required: No

<debuglevel>

Keyword 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.
See also: javac -G:[lines,vars,source]
  • Type: java.lang.String
  • Since: 2.1
  • Required: No

<enablePreview>

Set to true to enable preview language features of the java compiler
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 list of exclusion filters for the compiler.
  • Type: java.util.Set<java.lang.String>
  • Required: No

<executable>

Sets the executable of the compiler to use when fork is true.
  • Type: java.lang.String
  • Required: No

<failOnError>

Indicates whether the build will continue even if there are compilation errors.
  • Type: boolean
  • Since: 2.0.2
  • Required: No

<failOnWarning>

Indicates whether the build will continue even if there are compilation warnings.
  • Type: boolean
  • Since: 3.6
  • Required: No

<fileExtensions>

File extensions to check timestamp for incremental build. Default contains only class and jar.
  • Type: java.util.List<java.lang.String>
  • Since: 3.1
  • Required: No

<forceLegacyJavacApi>

The underlying compiler now uses javax.tools API if available in your current JDK. Set this to true to always use the legacy com.sun.tools.javac API instead.

This only has an effect for compilerId being javac and fork being false.

  • Type: boolean
  • Since: 3.13
  • Required: No

<fork>

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

<generatedSourcesDirectory>

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

  • Type: java.nio.file.Path
  • Since: 2.2
  • Required: No

<implicit>

Keyword to be appended to the -implicit: command-line switch.
See also: javac -implicit
  • Type: java.lang.String
  • Since: 3.10.2
  • Required: No

<includes>

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

<incrementalExcludes>

A list of exclusion filters for the incremental calculation.
  • Type: java.util.Set<java.lang.String>
  • Since: 3.11
  • Required: No

<jdkToolchain>

Specify the requirements for this jdk toolchain for using a different javac than the one of the JRE 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>
note: requires at least Maven 3.3.1
  • Type: java.util.Map<java.lang.String, java.lang.String>
  • Since: 3.6
  • Required: No

<maxmem>

Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" if fork is set to true.
  • Type: java.lang.String
  • Since: 2.0.1
  • Required: No

<meminitial>

Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" if fork is set to true.
  • Type: java.lang.String
  • Since: 2.0.1
  • Required: No

<mojoStatusPath>

No description.
  • Type: java.lang.String
  • Since: 3.0 needed for storing the status for the incremental build support.
  • Required: No

<multiReleaseOutput>

When set to true, the classes will be placed in META-INF/versions/${release} The release value must be set, otherwise the plugin will fail.

Note: A jar is only a multirelease 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 multirelease jar using the outputDirectory.
  • Type: boolean
  • Since: 3.7.1
  • Required: No

<optimize>

Deprecated.
This property is a no-op in javac.

Set to true to optimize the compiled code using the compiler's optimization methods.
  • Type: boolean
  • Required: No

<outputFileName>

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>

Timestamp for reproducible output archive entries, 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>

Set to true to generate metadata for reflection on method parameters.
See also: javac -parameters
  • Type: boolean
  • Since: 3.6.2
  • Required: No

<proc>

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.
  • full - annotation processing and compilation.
full is the default. Starting with JDK 21, this option must be set explicitly.
See also: javac -proc, javac Annotation Processing
  • Type: java.lang.String
  • Since: 2.2
  • Required: No

<release>

The -release argument for the Java compiler, supported since Java9
See also: javac -release
  • Type: java.lang.String
  • Since: 3.6
  • Required: No

<showCompilationChanges>

No description.
  • Type: boolean
  • Required: No

<showDeprecation>

Sets whether to show source locations where deprecated APIs are used.
  • Type: boolean
  • Required: No

<showWarnings>

Set to false to disable warnings during compilation.
  • 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>

No description.
  • Type: boolean
  • Since: 2.5
  • Required: No

<source>

The -source argument for the Java compiler.

NOTE:

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


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

<staleMillis>

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

<target>

The -target argument for the Java compiler.

NOTE:

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


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

<useIncrementalCompilation>

to enable/disable incremental compilation feature.

This leads to two different modes depending on the underlying compiler. The default javac compiler does the following:

  • true (default) in this mode the compiler plugin determines whether any JAR files the current module depends on have changed in the current build run; or any source file was added, removed or changed since the last compilation. If this is the case, the compiler plugin recompiles all sources.
  • false (not recommended) this only compiles source files which are newer than their corresponding class files, namely which have changed since the last compilation. This does not recompile other classes which use the changed class, potentially leaving them with references to methods that no longer exist, leading to errors at runtime.
  • Type: boolean
  • Since: 3.1
  • Required: No

<verbose>

Set to true to show messages about what the compiler is doing.
See also: javac -verbose
  • Type: boolean
  • Required: No