Class AbstractCompilerMojo
- All Implemented Interfaces:
org.apache.maven.api.plugin.Mojo
- Direct Known Subclasses:
CompilerMojo
,TestCompilerMojo
JavaCompiler
interface from JDK 6+.
Each instance shall be used only once, then discarded.
Thread-safety
This class is not thread-safe. If this class is used in a multi-thread context, users are responsible for synchronizing all accesses to this MOJO instance. However, the executor returned bycreateExecutor(DiagnosticListener)
can safely
launch the compilation in a background thread.- Since:
- 2.0
- Author:
- Trygve Laugstøl, Martin Desruisseaux
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List
<DependencyCoordinate> Deprecated.protected boolean
Deprecated.This flag is ignored.protected String[]
Class names of annotation processors to run.protected org.apache.maven.api.services.ArtifactManager
protected Path
The directory to run the compiler from if fork is true.Additional arguments to be passed verbatim to the Java compiler.protected String
Deprecated.UsecompilerArgs
instead.protected String
Identifier of the compiler to use.protected String
Deprecated, for removal: This API element is subject to removal in a future version.Not supported anymore.protected String
Deprecated, for removal: This API element is subject to removal in a future version.This parameter is no longer used by the underlying compilers.Deprecated.Replaced by the project-wide<sources>
element.protected boolean
Whether to generatepackage-info.class
even when empty.protected boolean
Deprecated.Setting this flag tofalse
is replaced by<debuglevel>none</debuglevel>
.protected String
Kinds of debugging information to include in the compiled class files.protected boolean
Whether to enable preview language features of the java compiler.protected String
The-encoding
argument for the Java compiler.protected String
Executable of the compiler to use whenfork
istrue
.protected boolean
Whether the build will stop if there are compilation errors.protected boolean
Whether the build will stop if there are compilation warnings.File extensions to check timestamp for incremental build.protected Boolean
Deprecated, for removal: This API element is subject to removal in a future version.Ignored becausejava.lang.Compiler
has been deprecated and removed from the JDK.protected Boolean
Deprecated, for removal: This API element is subject to removal in a future version.Ignored because the compiler plugin now always use thejavax.tools
API.protected boolean
Allows running the compiler in a separate process.protected String
Whether to generate class files for implicitly referenced files.protected String
The algorithm to use for selecting which files to compile.Requirements for this JDK toolchain for using a differentjavac
than the one of the JDK used by Maven.protected org.apache.maven.api.plugin.Log
The logger for reporting information or warnings to the user.protected String
Maximum size, in megabytes, of the memory allocation pool iffork
is set totrue
.protected String
Initial size, in megabytes, of the memory allocation pool iffork
is set totrue
.protected org.apache.maven.api.services.MessageBuilderFactory
protected String
The--module-version
argument for the Java compiler.protected Path
Path to a file where to cache information about the last incremental build.protected Boolean
Deprecated, for removal: This API element is subject to removal in a future version.This property is ignored.protected String
Deprecated, for removal: This API element is subject to removal in a future version.Bundling many class files into a single file should be done by other plugins.protected String
Deprecated, for removal: This API element is subject to removal in a future version.Not used by the compiler plugin since it does not generate archive.protected boolean
Whether to generate metadata for reflection on method parameters.protected String
Configures if annotation processing and/or compilation are performed by the compiler.protected org.apache.maven.api.Project
The current project instance.protected org.apache.maven.api.services.ProjectManager
protected String
The--release
argument for the Java compiler when the sources do not declare this version.protected org.apache.maven.api.Session
The current build session instance.protected boolean
Whether to provide more details about why a module is rebuilt.protected boolean
Whether to show source locations where deprecated APIs are used.protected boolean
Whether to show compilation warnings.protected Boolean
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated as a consequence ofcompilerReuseStrategy
deprecation.protected String
The--source
argument for the Java compiler.protected int
The granularity in milliseconds of the last modification date for testing whether a source needs recompilation.protected String
The--target
argument for the Java compiler.protected org.apache.maven.api.services.ToolchainManager
protected Boolean
Deprecated.Replaced byincrementalCompilation
.protected boolean
Whether to show messages about what the compiler is doing. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractCompilerMojo
(org.apache.maven.api.PathScope compileScope) Creates a new MOJO. -
Method Summary
Modifier and TypeMethodDescriptioncompiler()
Returns the compiler to use for compiling the code.createExecutor
(DiagnosticListener<? super JavaFileObject> listener) Creates a new task by taking a snapshot of the current configuration of this MOJO.void
execute()
Runs the Java compiler.protected abstract String
Returns the file where to dump the command-line when debug logging is enabled or when the compilation failed.Returns the exclusion filters for the compiler, or an empty list if none.protected abstract Path
Returns the path where to place generated source files created by annotation processing.Returns the inclusion filters for the compiler, or an empty list for all Java source files.Returns the exclusion filters for the incremental calculation.protected abstract Path
Returns the destination directory (or class output directory) for class files.protected String
Returns the--release
argument for the Java compiler.protected String
Returns the--source
argument for the Java compiler.protected String
Returns the--target
argument for the Java compiler.parseParameters
(OptionChecker compiler) Parses the parameters declared in the MOJO.
-
Field Details
-
moduleVersion
@Parameter(property="maven.compiler.moduleVersion", defaultValue="${project.version}") protected String moduleVersionThe--module-version
argument for the Java compiler. This is ignored if not applicable, e.g., in non-modular projects.- Since:
- 4.0.0
- See Also:
-
encoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") protected String encodingThe-encoding
argument for the Java compiler.- Since:
- 2.1
- See Also:
-
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:
-
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:
-
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:
If such<build> <sources> <source> <directory>src/main/java</directory> <targetVersion>17</targetVersion> </source> </sources> </build>
<targetVersion>
element is found, it has precedence over thisrelease
property. If a source does not declare a target Java version, then the value of thisrelease
property is used as a fallback. If omitted, the compiler will generate bytecodes for the Java version running the compiler.- Since:
- 3.6
- See Also:
-
enablePreview
@Parameter(property="maven.compiler.enablePreview", defaultValue="false") protected boolean enablePreviewWhether to enable preview language features of the java compiler. Iftrue
, then the--enable-preview
option will be added to compiler arguments.- Since:
- 3.10.1
- See Also:
-
compileSourceRoots
Deprecated.Replaced by the project-wide<sources>
element.The root directories containing the source files to be compiled. Ifnull
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
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):
Note that<compilerArgs> <arg>-Xlint</arg> <arg>-Xmaxerrs</arg> <arg>1000</arg> <arg>J-Duser.language=en_us</arg> </compilerArgs>
-J
options should be specified only iffork
is set totrue
. Other options can be specified regardless thefork
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.- Since:
- 3.1
- See Also:
-
compilerArgument
Deprecated.UsecompilerArgs
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 iffork
is set totrue
.- See Also:
-
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.
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 eitheronly
orfull
is set. So literally the default isnone
. It is recommended to always list the annotation processors you want to execute instead of using theproc
configuration, to ensure that only desired processors are executed and not any "hidden" (and maybe malicious).- Since:
- 2.2
- See Also:
-
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.- Since:
- 2.2
- See Also:
-
annotationProcessorPaths
Deprecated.Replaced by ordinary dependencies with<type>
element set toprocessor
,classpath-processor
ormodular-processor
.Classpath elements to supply as annotation processor path. If specified, the compiler will detect annotation processors only in those classpath elements. If omitted (andproc
is set toonly
orfull
), the default classpath is used to detect annotation processors. The detection itself depends on the configuration ofannotationProcessors
. 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 orannotationProcessorPaths
.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.- Since:
- 3.5
- See Also:
-
annotationProcessorPathsUseDepMgmt
@Deprecated(since="4.0.0") @Parameter(defaultValue="false") protected boolean annotationProcessorPathsUseDepMgmtDeprecated.This flag is ignored. Replaced by ordinary dependencies with<type>
element set toprocessor
,classpath-processor
ormodular-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.
- Since:
- 3.12.0
-
createMissingPackageInfoClass
@Parameter(property="maven.compiler.createMissingPackageInfoClass", defaultValue="false") protected boolean createMissingPackageInfoClassWhether to generatepackage-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.- Since:
- 3.10
- See Also:
-
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.
- Since:
- 3.10.2
- See Also:
-
parameters
@Parameter(property="maven.compiler.parameters", defaultValue="false") protected boolean parametersWhether to generate metadata for reflection on method parameters. Iftrue
, the-parameters
option will be added to compiler arguments.- Since:
- 3.6.2
- See Also:
-
debug
@Deprecated(since="4.0.0") @Parameter(property="maven.compiler.debug", defaultValue="true") protected boolean debugDeprecated.Setting this flag tofalse
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 thedebuglevel
parameter. If thisdebug
flag istrue
, then the-g
option may be added to compiler arguments with a value determined by thedebuglevel
argument. If thisdebug
flag isfalse
, then the-g:none
option will be added to the compiler arguments.- See Also:
-
debuglevel
Kinds of debugging information to include in the compiled class files. Legal values arelines
,vars
,source
,all
andnone
. Values other thanall
andnone
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 (typicallylines
andsource
but notvars
).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.- Since:
- 2.1
- See Also:
-
optimize
@Deprecated(forRemoval=true) @Parameter(property="maven.compiler.optimize") protected Boolean optimizeDeprecated, for removal: This API element is subject to removal in a future version.This property is ignored.Whether to optimize the compiled code using the compiler's optimization methods. -
verbose
@Parameter(property="maven.compiler.verbose", defaultValue="false") protected boolean verboseWhether to show messages about what the compiler is doing. Iftrue
, then the-verbose
option will be added to compiler arguments. In addition, files such astarget/javac.args
will be generated even on successful compilation.- See Also:
-
showCompilationChanges
@Parameter(property="maven.compiler.showCompilationChanges", defaultValue="false") protected boolean showCompilationChangesWhether to provide more details about why a module is rebuilt. This is used only ifincrementalCompilation
is set to something else than"none"
.- See Also:
-
showDeprecation
@Parameter(property="maven.compiler.showDeprecation", defaultValue="false") protected boolean showDeprecationWhether to show source locations where deprecated APIs are used. Iftrue
, then the-deprecation
option will be added to compiler arguments. That option is itself a shorthand for-Xlint:deprecation
.- See Also:
-
showWarnings
@Parameter(property="maven.compiler.showWarnings", defaultValue="true") protected boolean showWarningsWhether to show compilation warnings. Iffalse
, then the-nowarn
option will be added to compiler arguments. That option is itself a shorthand for-Xlint:none
.- See Also:
-
failOnWarning
@Parameter(property="maven.compiler.failOnWarning", defaultValue="false") protected boolean failOnWarningWhether the build will stop if there are compilation warnings. Iftrue
, then the-Werror
option will be added to compiler arguments.- Since:
- 3.6
- See Also:
-
failOnError
@Parameter(property="maven.compiler.failOnError", defaultValue="true") protected boolean failOnErrorWhether the build will stop if there are compilation errors.- Since:
- 2.0.2
- See Also:
-
outputFileName
Deprecated, for removal: This API element is subject to removal in a future version.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
@Deprecated(since="4.0.0", forRemoval=true) @Parameter(defaultValue="${project.build.outputTimestamp}") protected String outputTimestampDeprecated, for removal: This API element is subject to removal in a future version.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 8601yyyy-MM-dd'T'HH:mm:ssXXX
or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).- Since:
- 3.12.0
-
incrementalCompilation
@Parameter(property="maven.compiler.incrementalCompilation") protected String incrementalCompilationThe algorithm to use for selecting which files to compile. Values can bedependencies
,sources
,classes
,rebuild-on-change
,rebuild-on-add
,modules
ornone
.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
andclasses
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 withsources
orclasses
. When used withclasses
, it provides a way to detect class renaming (this is not needed withsources
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 withsources
orclasses
. It does not rebuild when a new source file is added without change in other files, unlessrebuild-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.- Since:
- 4.0.0
- See Also:
-
useIncrementalCompilation
@Deprecated(since="4.0.0") @Parameter(property="maven.compiler.useIncrementalCompilation") protected Boolean useIncrementalCompilationDeprecated.Replaced byincrementalCompilation
. A value oftrue
in this old property is equivalent to"dependencies,sources,rebuild-on-add"
in the new property, and a value offalse
is equivalent to"classes"
.Whether to enable/disable incremental compilation feature.- Since:
- 3.1
-
fileExtensions
File extensions to check timestamp for incremental build. Default contains onlyclass
andjar
. TODO: Rename with a name making clearer that this parameter is about incremental build.- Since:
- 3.1
- See Also:
-
staleMillis
@Parameter(property="lastModGranularityMs", defaultValue="0") protected int staleMillisThe granularity in milliseconds of the last modification date for testing whether a source needs recompilation.- See Also:
-
fork
@Parameter(property="maven.compiler.fork", defaultValue="false") protected boolean forkAllows running the compiler in a separate process. Iffalse
, the plugin uses the built-in compiler, while iftrue
it will use an executable.- See Also:
-
jdkToolchain
Requirements for this JDK toolchain for using a differentjavac
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>
- Since:
- 3.6
- See Also:
-
compilerId
Identifier of the compiler to use. This identifier shall match the identifier of a compiler known to the JDK tool chain, or the name of aJavaCompiler
instance registered as a service findable byServiceLoader
. See this guide for more information. If unspecified, then the system Java compiler is used. The identifier of the system Java compiler is usuallyjavac
.- See Also:
-
compilerVersion
@Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.compilerVersion") protected String compilerVersionDeprecated, for removal: This API element is subject to removal in a future version.This parameter is no longer used by the underlying compilers.Version of the compiler to use iffork
is set totrue
. Examples! "1.3", "1.5".- See Also:
-
forceLegacyJavacApi
@Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.forceLegacyJavacApi") protected Boolean forceLegacyJavacApiDeprecated, for removal: This API element is subject to removal in a future version.Ignored because the compiler plugin now always use thejavax.tools
API.Whether to use the legacycom.sun.tools.javac
API instead ofjavax.tools
API.- Since:
- 3.13
- See Also:
-
forceJavacCompilerUse
@Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.forceJavacCompilerUse") protected Boolean forceJavacCompilerUseDeprecated, for removal: This API element is subject to removal in a future version.Ignored becausejava.lang.Compiler
has been deprecated and removed from the JDK.Whether to use legacy compiler API.- Since:
- 3.0
-
compilerReuseStrategy
@Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.compilerReuseStrategy") protected String compilerReuseStrategyDeprecated, for removal: This API element is subject to removal in a future version.Not supported anymore. The reuse ofJavaFileManager
instance is plugin implementation details.Strategy to re usejavacc
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.
- Since:
- 2.5
-
skipMultiThreadWarning
@Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.skipMultiThreadWarning") protected Boolean skipMultiThreadWarningDeprecated, for removal: This API element is subject to removal in a future version.Deprecated as a consequence ofcompilerReuseStrategy
deprecation.- Since:
- 2.5
-
executable
Executable of the compiler to use whenfork
istrue
. If this parameter is specified, then thejdkToolchain
is ignored.- See Also:
-
meminitial
Initial size, in megabytes, of the memory allocation pool iffork
is set totrue
. Examples: "64", "64M". Suffixes "k" (for kilobytes) and "G" (for gigabytes) are also accepted. If no suffix is provided, "M" is assumed.- Since:
- 2.0.1
- See Also:
-
maxmem
Maximum size, in megabytes, of the memory allocation pool iffork
is set totrue
. Examples: "128", "128M". Suffixes "k" (for kilobytes) and "G" (for gigabytes) are also accepted. If no suffix is provided, "M" is assumed.- Since:
- 2.0.1
- See Also:
-
basedir
The directory to run the compiler from if fork is true. -
mojoStatusPath
@Parameter(defaultValue="${project.build.directory}/maven-status/${mojo.plugin.descriptor.artifactId}/${mojo.executionId}.cache", required=true, readonly=true) protected Path mojoStatusPathPath to a file where to cache information about the last incremental build. This is used when "incremental" builds are enabled for detecting additions or removals of source files, or changes in plugin configuration. This file should be in the output directory and can be deleted at any time -
session
@Inject protected org.apache.maven.api.Session sessionThe current build session instance. -
project
@Inject protected org.apache.maven.api.Project projectThe current project instance. -
projectManager
@Inject protected org.apache.maven.api.services.ProjectManager projectManager -
artifactManager
@Inject protected org.apache.maven.api.services.ArtifactManager artifactManager -
toolchainManager
@Inject protected org.apache.maven.api.services.ToolchainManager toolchainManager -
messageBuilderFactory
@Inject protected org.apache.maven.api.services.MessageBuilderFactory messageBuilderFactory -
logger
@Inject protected org.apache.maven.api.plugin.Log loggerThe logger for reporting information or warnings to the user. Currently, this is also used for console output.Thread safety
This logger should be thread-safe if theToolExecutor
is executed in a background thread.
-
-
Constructor Details
-
AbstractCompilerMojo
protected AbstractCompilerMojo(org.apache.maven.api.PathScope compileScope) Creates a new MOJO.- Parameters:
compileScope
-MAIN_COMPILE
orTEST_COMPILE
-
-
Method Details
-
getIncludes
Returns the inclusion filters for the compiler, or an empty list for all Java source files. The filter patterns are described inFileSystem.getPathMatcher(String)
. If no syntax is specified, the default syntax is a derivative of "glob" compatible with the behavior of Maven 3.- Returns:
- the inclusion filters for the compiler, or an empty list for all Java source files
-
getExcludes
Returns the exclusion filters for the compiler, or an empty list if none. The filter patterns are described inFileSystem.getPathMatcher(String)
. If no syntax is specified, the default syntax is a derivative of "glob" compatible with the behavior of Maven 3.- Returns:
- the exclusion filters for the compiler, or an empty list if none
-
getIncrementalExcludes
Returns the exclusion filters for the incremental calculation. Updated source files, if excluded by this filter, will not cause the project to be rebuilt.- Returns:
- the exclusion filters for the incremental calculation
- See Also:
-
getOutputDirectory
Returns the destination directory (or class output directory) for class files. This directory will be given to the-d
Java compiler option.- Returns:
- the destination directory (or class output directory) for class files
-
getSource
Returns the--source
argument for the Java compiler. The default implementation returns thesource
value.- Returns:
- the
--source
argument for the Java compiler
-
getTarget
Returns the--target
argument for the Java compiler. The default implementation returns thetarget
value.- Returns:
- the
--target
argument for the Java compiler
-
getRelease
Returns the--release
argument for the Java compiler. The default implementation returns therelease
value.- Returns:
- the
--release
argument for the Java compiler
-
getGeneratedSourcesDirectory
Returns the path where to place generated source files created by annotation processing.- Returns:
- the path where to place generated source files created by annotation processing
-
getDebugFileName
Returns the file where to dump the command-line when debug logging is enabled or when the compilation failed. For example, if the value is"javac"
, then the Java compiler can be launched from the command-line by typingjavac @target/javac.args
. The debug file will contain the compiler options together with the list of source files to compile.Note: debug logging should not be confused with the
debug
flag.- Returns:
- the file where to dump the command-line when debug logging is enabled or when the compilation failed
- See Also:
-
execute
public void execute() throws org.apache.maven.api.plugin.MojoExceptionRuns the Java compiler. This method performs the following steps:- Get a Java compiler by a call to
compiler()
. - Get the options to give to the compiler by a call to
parseParameters(OptionChecker)
. - Get an executor with
createExecutor(DiagnosticListener)
with the default listener. - Apply the incremental build if enabled.
- Execute the compilation.
- Shows messages in the logger.
- Specified by:
execute
in interfaceorg.apache.maven.api.plugin.Mojo
- Throws:
org.apache.maven.api.plugin.MojoException
- if the compiler cannot be run
- Get a Java compiler by a call to
-
createExecutor
public ToolExecutor createExecutor(DiagnosticListener<? super JavaFileObject> listener) throws IOException Creates a new task by taking a snapshot of the current configuration of this MOJO. This method creates the output directory if it does not already exist.Multi-threading
This method and the returned objects are not thread-safe. However, this method takes a snapshot of the configuration of this MOJO. Changes in this MOJO after this method call will not affect the returned executor. Therefore, the executor can safely be executed in a background thread, provided that thelogger
is thread-safe.- Parameters:
listener
- where to send compilation warnings, ornull
for the Maven logger- Returns:
- the task to execute for compiling the project using the configuration in this MOJO
- Throws:
org.apache.maven.api.plugin.MojoException
- if this method identifies an invalid parameter in this MOJOIOException
- if an error occurred while creating the output directory or scanning the source directoriesorg.apache.maven.api.services.MavenException
- if an error occurred while fetching dependencies
-
compiler
Returns the compiler to use for compiling the code. Iffork
istrue
, the returned compiler will be a wrapper for a command line. Otherwise, it will be the compiler identified bycompilerId
if a value was supplied, or the standard compiler provided with the Java platform otherwise.- Returns:
- the compiler to use for compiling the code
- Throws:
org.apache.maven.api.plugin.MojoException
- if no compiler was found
-
parseParameters
Parses the parameters declared in the MOJO. Therelease
parameter is excluded because it is handled in a special way in order to support the compilation of multi-version projects.- Parameters:
compiler
- the tools to use for verifying the validity of options- Returns:
- the options after validation
-
<type>
element set toprocessor
,classpath-processor
ormodular-processor
.