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
FieldsModifier and TypeFieldDescriptionprotected List<DependencyCoordinate> Classpath elements to supply as annotation processor path.protected booleanWhether 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.ArtifactManagerprotected PathThe directory to run the compiler from if fork is true.protected PathThe target directory of the compiler if fork is true.Sets the arguments to be passed to the compiler.protected StringSets the unformatted single argument string to be passed to the compiler.protected StringThe compiler id of the compiler to use.protected org.codehaus.plexus.compiler.manager.CompilerManagerPlexus compiler manager.protected StringStrategy 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 StringDeprecated.protected booleanPackage 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 booleanSet totrueto include debugging information in the compiled class files.protected booleanSet totrueto enable preview language features of the java compilerprotected StringThe-encodingargument for the Java compiler.protected StringSets the executable of the compiler to use whenforkistrue.protected booleanIndicates whether the build will continue even if there are compilation errors.protected booleanIndicates whether the build will continue even if there are compilation warnings.File extensions to check timestamp for incremental build.protected booleanThe underlying compiler now usesjavax.toolsAPI if available in your current JDK.protected booleanAllows running the compiler in a separate process.protected StringKeyword to be appended to the-implicit:command-line switch.Specify the requirements for this jdk toolchain for using a differentjavacthan the one of the JRE used by Maven.protected org.apache.maven.api.plugin.Logprotected StringSets the maximum size, in megabytes, of the memory allocation pool, ex.protected StringInitial size, in megabytes, of the memory allocation pool, ex.protected org.apache.maven.api.services.MessageBuilderFactoryprotected Stringprotected booleanDeprecated.This property is a no-op injavac.protected StringTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).protected booleanSet totrueto generate metadata for reflection on method parameters.protected StringSets whether annotation processing is performed or not.protected org.apache.maven.api.ProjectThe current project instance.protected org.apache.maven.api.services.ProjectManagerprotected static final Stringprotected StringThe-releaseargument for the Java compiler, supported since Java9protected org.apache.maven.api.SessionThe current build session instance.protected booleanprotected booleanSets whether to show source locations where deprecated APIs are used.protected booleanSet tofalseto disable warnings during compilation.protected booleanprotected StringThe-sourceargument for the Java compiler.protected intSets the granularity in milliseconds of the last modification date for testing whether a source needs recompilation.protected StringThe-targetargument for the Java compiler.protected org.apache.maven.api.services.ToolchainManagerprotected booleanto enable/disable incremental compilation feature.protected booleanSet totrueto show messages about what the compiler is doing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()protected Instantprotected abstract Stringprotected abstract Stringprotected abstract Pathprotected org.apache.maven.api.plugin.LoggetLog()getModuleDeclaration(Set<Path> sourceFiles) protected abstract Pathprotected final org.apache.maven.api.Projectprotected abstract Stringprotected inttry to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependentprotected abstract Stringprotected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScannergetSourceInclusionScanner(int staleMillis) protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScannergetSourceInclusionScanner(String inputFileEnding) protected abstract Stringprotected final Optional<org.apache.maven.api.Toolchain> protected booleanWe 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 booleanprotected abstract voidpreparePaths(Set<Path> sourceFiles) voidsetRelease(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 totrueto include debugging information in the compiled class files.- See Also:
-
parameters
@Parameter(property="maven.compiler.parameters", defaultValue="false") protected boolean parametersSet totrueto generate metadata for reflection on method parameters.- Since:
- 3.6.2
- See Also:
-
enablePreview
@Parameter(property="maven.compiler.enablePreview", defaultValue="false") protected boolean enablePreviewSet totrueto 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 totrueto 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 totrueto optimize the compiled code using the compiler's optimization methods. -
showWarnings
@Parameter(property="maven.compiler.showWarnings", defaultValue="true") protected boolean showWarningsSet tofalseto disable warnings during compilation. -
source
The
-sourceargument 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
-targetargument 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-releaseargument for the Java compiler, supported since Java9- Since:
- 3.6
- See Also:
-
encoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") protected String encodingThe-encodingargument 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 thejavacbinary is automatically retrieved.Version of the compiler to use, ex. "1.3", "1.5", ifforkis set totrue. -
fork
@Parameter(property="maven.compiler.fork", defaultValue="false") protected boolean forkAllows running the compiler in a separate process. Iffalseit uses the built in compiler, while iftrueit will use an executable. -
meminitial
Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" ifforkis set totrue.- Since:
- 2.0.1
-
maxmem
Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" ifforkis set totrue.- Since:
- 2.0.1
-
executable
Sets the executable of the compiler to use whenforkistrue. -
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.
fullis 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:-Joptions are only passed through ifforkis 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
-Joptions are only passed through ifforkis 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)javacthan 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.toolsAPI if available in your current JDK. Set this totrueto always use the legacycom.sun.tools.javacAPI instead.This only has an effect for
compilerIdbeingjavacandforkbeingfalse.- 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 onlyclassandjar.- 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 oftruecauses 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:ssXXXor 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:
executein 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:
trueif at least one single dependency has changed.
-
setTarget
-
setRelease
-
getModuleDeclaration
-
getLog
protected org.apache.maven.api.plugin.Log getLog()
-
javacbinary is automatically retrieved.