Class AbstractCompilerMojo
- All Implemented Interfaces:
org.apache.maven.api.plugin.Mojo
- Direct Known Subclasses:
CompilerMojo
,TestCompilerMojo
- Since:
- 2.0
- Author:
- others, Trygve Laugstøl
-
Field Summary
Modifier and TypeFieldDescriptionprotected List
<DependencyCoordinate> Classpath elements to supply as annotation processor path.protected boolean
Whether to use the Maven dependency management section when resolving transitive dependencies of annotation processor paths.protected String[]
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.protected Path
The target directory of the compiler if fork is true.Sets the arguments to be passed to the compiler.protected String
Sets the unformatted single argument string to be passed to the compiler.protected String
The compiler id of the compiler to use.protected org.codehaus.plexus.compiler.manager.CompilerManager
Plexus compiler manager.protected String
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 instancereuseSame
: the same Javacc class will be used for each compilation even for multi-threaded buildalwaysNew
: 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.protected String
Deprecated.protected boolean
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.protected boolean
Set totrue
to include debugging information in the compiled class files.protected boolean
Set totrue
to enable preview language features of the java compilerprotected String
The-encoding
argument for the Java compiler.protected String
Sets the executable of the compiler to use whenfork
istrue
.protected boolean
Indicates whether the build will continue even if there are compilation errors.protected boolean
Indicates whether the build will continue even if there are compilation warnings.File extensions to check timestamp for incremental build.protected boolean
The underlying compiler now usesjavax.tools
API if available in your current JDK.protected boolean
Allows running the compiler in a separate process.protected String
Keyword to be appended to the-implicit:
command-line switch.Specify the requirements for this jdk toolchain for using a differentjavac
than the one of the JRE used by Maven.protected org.apache.maven.api.plugin.Log
protected String
Sets the maximum size, in megabytes, of the memory allocation pool, ex.protected String
Initial size, in megabytes, of the memory allocation pool, ex.protected org.apache.maven.api.services.MessageBuilderFactory
protected String
protected boolean
Deprecated.This property is a no-op injavac
.protected String
Timestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXX
or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).protected boolean
Set totrue
to generate metadata for reflection on method parameters.protected String
Sets whether annotation processing is performed or not.protected org.apache.maven.api.Project
The current project instance.protected org.apache.maven.api.services.ProjectManager
protected static final String
protected String
The-release
argument for the Java compiler, supported since Java9protected org.apache.maven.api.Session
The current build session instance.protected boolean
protected boolean
Sets whether to show source locations where deprecated APIs are used.protected boolean
Set tofalse
to disable warnings during compilation.protected boolean
protected String
The-source
argument for the Java compiler.protected int
Sets 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
to enable/disable incremental compilation feature.protected boolean
Set totrue
to show messages about what the compiler is doing. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute()
protected Instant
protected abstract String
protected abstract String
protected abstract Path
protected org.apache.maven.api.plugin.Log
getLog()
getModuleDeclaration
(Set<Path> sourceFiles) protected abstract Path
protected final org.apache.maven.api.Project
protected abstract String
protected int
try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependentprotected abstract String
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner
getSourceInclusionScanner
(int staleMillis) protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner
getSourceInclusionScanner
(String inputFileEnding) protected abstract String
protected final Optional
<org.apache.maven.api.Toolchain> protected boolean
We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own generated classes and if we got a file which is >= the build-started timestamp, then we caught a file which got changed during this build.protected boolean
protected abstract void
preparePaths
(Set<Path> sourceFiles) void
setRelease
(String release) void
-
Field Details
-
PS
-
failOnError
@Parameter(property="maven.compiler.failOnError", defaultValue="true") protected boolean failOnErrorIndicates whether the build will continue even if there are compilation errors.- Since:
- 2.0.2
-
failOnWarning
@Parameter(property="maven.compiler.failOnWarning", defaultValue="false") protected boolean failOnWarningIndicates whether the build will continue even if there are compilation warnings.- Since:
- 3.6
-
debug
@Parameter(property="maven.compiler.debug", defaultValue="true") protected boolean debugSet totrue
to include debugging information in the compiled class files.- See Also:
-
parameters
@Parameter(property="maven.compiler.parameters", defaultValue="false") protected boolean parametersSet totrue
to generate metadata for reflection on method parameters.- Since:
- 3.6.2
- See Also:
-
enablePreview
@Parameter(property="maven.compiler.enablePreview", defaultValue="false") protected boolean enablePreviewSet totrue
to enable preview language features of the java compiler- Since:
- 3.10.1
- See Also:
-
verbose
@Parameter(property="maven.compiler.verbose", defaultValue="false") protected boolean verboseSet totrue
to show messages about what the compiler is doing.- See Also:
-
showDeprecation
@Parameter(property="maven.compiler.showDeprecation", defaultValue="false") protected boolean showDeprecationSets whether to show source locations where deprecated APIs are used. -
optimize
@Deprecated @Parameter(property="maven.compiler.optimize", defaultValue="false") protected boolean optimizeDeprecated.This property is a no-op injavac
.Set totrue
to optimize the compiled code using the compiler's optimization methods. -
showWarnings
@Parameter(property="maven.compiler.showWarnings", defaultValue="true") protected boolean showWarningsSet tofalse
to disable warnings during compilation. -
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:
-
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:
-
release
The-release
argument for the Java compiler, supported since Java9- Since:
- 3.6
- See Also:
-
encoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") protected String encodingThe-encoding
argument for the Java compiler.- Since:
- 2.1
- See Also:
-
staleMillis
@Parameter(property="lastModGranularityMs", defaultValue="0") protected int staleMillisSets the granularity in milliseconds of the last modification date for testing whether a source needs recompilation. -
compilerId
The compiler id of the compiler to use. See this guide for more information. -
compilerVersion
Deprecated.This parameter is no longer evaluated by the underlying compilers, instead the actual version of thejavac
binary is automatically retrieved.Version of the compiler to use, ex. "1.3", "1.5", iffork
is set totrue
. -
fork
@Parameter(property="maven.compiler.fork", defaultValue="false") protected boolean forkAllows running the compiler in a separate process. Iffalse
it uses the built in compiler, while iftrue
it will use an executable. -
meminitial
Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" iffork
is set totrue
.- Since:
- 2.0.1
-
maxmem
Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" iffork
is set totrue
.- Since:
- 2.0.1
-
executable
Sets the executable of the compiler to use whenfork
istrue
. -
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.- Since:
- 2.2
- See Also:
-
annotationProcessors
Names of annotation processors to run. Only applies to JDK 1.6+ If not set, the default annotation processors discovery process applies.
- Since:
- 2.2
- See Also:
-
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.- Since:
- 3.5
- See Also:
-
annotationProcessorPathsUseDepMgmt
@Parameter(defaultValue="false") protected boolean annotationProcessorPathsUseDepMgmtWhether 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
-
compilerArgs
Sets the arguments to be passed to the compiler.
Note that
Example:-J
options are only passed through iffork
is set totrue
.<compilerArgs> <arg>-Xmaxerrs</arg> <arg>1000</arg> <arg>-Xlint</arg> <arg>-J-Duser.language=en_us</arg> </compilerArgs>
- Since:
- 3.1
- See Also:
-
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 usecompilerArgs
.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 iffork
is set totrue
.- See Also:
-
implicit
Keyword to be appended to the-implicit:
command-line switch.- Since:
- 3.10.2
- See Also:
-
jdkToolchain
Specify the requirements for this jdk toolchain for using a different
(see Guide to Toolchains for more info)javac
than the one of the JRE used by Maven. This overrules the toolchain selected by the maven-toolchain-plugin.<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- Since:
- 3.6
-
basedir
The directory to run the compiler from if fork is true. -
buildDirectory
@Parameter(defaultValue="${project.build.directory}", required=true, readonly=true) protected Path buildDirectoryThe target directory of the compiler if fork is true. -
compilerManager
@Inject protected org.codehaus.plexus.compiler.manager.CompilerManager compilerManagerPlexus compiler manager. -
session
@Inject protected org.apache.maven.api.Session sessionThe current build session instance. This is used for toolchain manager API calls. -
project
@Inject protected org.apache.maven.api.Project projectThe current project instance. This is used for propagating generated-sources paths as compile/testCompile source roots. -
compilerReuseStrategy
@Parameter(defaultValue="${reuseCreated}", property="maven.compiler.compilerReuseStrategy") protected String compilerReuseStrategyStrategy 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 instancereuseSame
: the same Javacc class will be used for each compilation even for multi-threaded buildalwaysNew
: a new Javacc class will be created for each compilation
- Since:
- 2.5
-
skipMultiThreadWarning
@Parameter(defaultValue="false", property="maven.compiler.skipMultiThreadWarning") protected boolean skipMultiThreadWarning- Since:
- 2.5
-
forceLegacyJavacApi
@Parameter(defaultValue="false", property="maven.compiler.forceLegacyJavacApi") protected boolean forceLegacyJavacApiThe underlying compiler now usesjavax.tools
API if available in your current JDK. Set this totrue
to always use the legacycom.sun.tools.javac
API instead.This only has an effect for
compilerId
beingjavac
andfork
beingfalse
.- Since:
- 3.13
-
mojoStatusPath
@Parameter(defaultValue="maven-status/${mojo.plugin.descriptor.artifactId}/${mojo.goal}/${mojo.executionId}") protected String mojoStatusPath- Since:
- 3.0 needed for storing the status for the incremental build support.
-
fileExtensions
File extensions to check timestamp for incremental build. Default contains onlyclass
andjar
.- Since:
- 3.1
-
useIncrementalCompilation
@Parameter(defaultValue="true", property="maven.compiler.useIncrementalCompilation") protected boolean useIncrementalCompilationto 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.
- Since:
- 3.1
-
createMissingPackageInfoClass
@Parameter(defaultValue="true", property="maven.compiler.createMissingPackageInfoClass") protected boolean createMissingPackageInfoClassPackage 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 oftrue
causes an empty class file to be generated. This behavior can be changed by setting this parameter tofalse
.- Since:
- 3.10
-
showCompilationChanges
@Parameter(defaultValue="false", property="maven.compiler.showCompilationChanges") protected boolean showCompilationChanges -
outputTimestamp
Timestamp for reproducible output archive entries, 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
-
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 logger
-
-
Constructor Details
-
AbstractCompilerMojo
public AbstractCompilerMojo()
-
-
Method Details
-
getSourceInclusionScanner
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner(int staleMillis) -
getSourceInclusionScanner
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner(String inputFileEnding) -
getClasspathElements
-
getModulepathElements
-
getPathElements
-
getCompileSourceRoots
-
preparePaths
-
getOutputDirectory
-
getSource
-
getTarget
-
getRelease
-
getCompilerArgument
-
getGeneratedSourcesDirectory
-
getDebugFileName
-
getProject
protected final org.apache.maven.api.Project getProject() -
execute
public void execute()- Specified by:
execute
in interfaceorg.apache.maven.api.plugin.Mojo
-
isTestCompile
protected boolean isTestCompile() -
getIncludes
-
getExcludes
-
getRequestThreadCount
protected int getRequestThreadCount()try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependent- Returns:
- number of thread for this build or 1 if not multi-thread build
-
getBuildStartTime
-
getToolchain
-
isDependencyChanged
protected boolean isDependencyChanged()We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own generated classes and if we got a file which is >= the build-started timestamp, then we caught a file which got changed during this build.- Returns:
true
if at least one single dependency has changed.
-
setTarget
-
setRelease
-
getModuleDeclaration
-
getLog
protected org.apache.maven.api.plugin.Log getLog()
-
javac
binary is automatically retrieved.