public abstract class AbstractCompilerMojo
extends org.apache.maven.plugin.AbstractMojo
Modifier and Type | Field and Description |
---|---|
private java.util.List<DependencyCoordinate> |
annotationProcessorPaths
Classpath elements to supply as annotation processor path.
|
private java.lang.String[] |
annotationProcessors
Names of annotation processors to run.
|
private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager |
artifactHandlerManager
Artifact handler manager.
|
private java.io.File |
basedir
The directory to run the compiler from if fork is true.
|
private java.io.File |
buildDirectory
The target directory of the compiler if fork is true.
|
protected java.util.List<java.lang.String> |
compilerArgs
Sets the arguments to be passed to the compiler if
fork is set to true . |
protected java.lang.String |
compilerArgument
Sets the unformatted single argument string to be passed to the compiler if
fork is set to
true . |
protected java.util.Map<java.lang.String,java.lang.String> |
compilerArguments
Deprecated.
use
compilerArgs instead. |
private java.lang.String |
compilerId
The compiler id of the compiler to use.
|
private org.codehaus.plexus.compiler.manager.CompilerManager |
compilerManager
Plexus compiler manager.
|
private java.lang.String |
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. |
private java.lang.String |
compilerVersion
Version of the compiler to use, ex.
|
private boolean |
debug
Set to
true to include debugging information in the compiled class files. |
private java.lang.String |
debuglevel
Keyword list to be appended to the
-g command-line switch. |
(package private) static java.lang.String |
DEFAULT_SOURCE |
(package private) static java.lang.String |
DEFAULT_TARGET |
private java.lang.String |
encoding
The -encoding argument for the Java compiler.
|
private java.lang.String |
executable
Sets the executable of the compiler to use when
fork is true . |
private boolean |
failOnError
Indicates whether the build will continue even if there are compilation errors.
|
private boolean |
failOnWarning
Indicates whether the build will continue even if there are compilation warnings.
|
private java.util.List<java.lang.String> |
fileExtensions
file extensions to check timestamp for incremental build
default contains only
.class |
private boolean |
forceJavacCompilerUse
compiler can now use javax.tools if available in your current jdk, you can disable this feature
using -Dmaven.compiler.forceJavacCompilerUse=true or in the plugin configuration
|
private boolean |
fork
Allows running the compiler in a separate process.
|
private java.util.Map<java.lang.String,java.lang.String> |
jdkToolchain
Specify the requirements for this jdk toolchain.
|
private java.lang.String |
maxmem
Sets the maximum size, in megabytes, of the memory allocation pool, ex.
|
private java.lang.String |
meminitial
Initial size, in megabytes, of the memory allocation pool, ex.
|
(package private) static java.lang.String |
MODULE_INFO_TARGET |
private org.apache.maven.plugin.MojoExecution |
mojoExecution |
private boolean |
optimize
Set to
true to optimize the compiled code using the compiler's optimization methods. |
private java.lang.String |
outputFileName
Sets the name of the output file when compiling a set of
sources to a single file.
|
private boolean |
parameters
Set to
true to generate metadata for reflection on method parameters. |
private java.lang.String |
proc
Sets whether annotation processing is performed or not.
|
private org.apache.maven.project.MavenProject |
project
The current project instance.
|
protected static java.lang.String |
PS |
protected java.lang.String |
release
The -release argument for the Java compiler, supported since Java9
|
private org.apache.maven.repository.RepositorySystem |
repositorySystem
Resolves the artifacts needed.
|
private org.apache.maven.artifact.resolver.ResolutionErrorHandler |
resolutionErrorHandler
Throws an exception on artifact resolution errors.
|
private org.apache.maven.execution.MavenSession |
session
The current build session instance.
|
private boolean |
showDeprecation
Sets whether to show source locations where deprecated APIs are used.
|
private boolean |
showWarnings
Set to
true to show compilation warnings. |
private boolean |
skipMultiThreadWarning |
protected java.lang.String |
source
The -source argument for the Java compiler.
|
private int |
staleMillis
Sets the granularity in milliseconds of the last modification
date for testing whether a source needs recompilation.
|
protected java.lang.String |
target
The -target argument for the Java compiler.
|
private org.apache.maven.toolchain.ToolchainManager |
toolchainManager |
private boolean |
useIncrementalCompilation
to enable/disable incrementation compilation feature
|
private boolean |
verbose
Set to
true to show messages about what the compiler is doing. |
Constructor and Description |
---|
AbstractCompilerMojo() |
Modifier and Type | Method and Description |
---|---|
private java.util.Set<java.io.File> |
computeStaleSources(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration,
org.codehaus.plexus.compiler.Compiler compiler,
org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner scanner) |
protected org.codehaus.plexus.compiler.CompilerResult |
convertToCompilerResult(java.util.List<org.codehaus.plexus.compiler.CompilerError> compilerErrors) |
void |
execute() |
protected java.util.Date |
getBuildStartTime() |
protected abstract java.util.List<java.lang.String> |
getClasspathElements() |
protected abstract java.lang.String |
getCompilerArgument() |
protected abstract java.util.Map<java.lang.String,java.lang.String> |
getCompilerArguments() |
protected abstract java.util.List<java.lang.String> |
getCompileSourceRoots() |
private java.util.Set<java.io.File> |
getCompileSources(org.codehaus.plexus.compiler.Compiler compiler,
org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration) |
protected abstract java.io.File |
getGeneratedSourcesDirectory() |
private java.lang.String |
getMemoryValue(java.lang.String setting) |
protected abstract java.util.List<java.lang.String> |
getModulepathElements() |
protected abstract java.io.File |
getOutputDirectory() |
protected abstract java.util.Map<java.lang.String,org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor> |
getPathElements() |
protected org.apache.maven.project.MavenProject |
getProject() |
protected abstract java.lang.String |
getRelease() |
protected int |
getRequestThreadCount()
try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependent
|
protected abstract java.lang.String |
getSource() |
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner |
getSourceInclusionScanner(int staleMillis) |
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner |
getSourceInclusionScanner(java.lang.String inputFileEnding) |
private org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping |
getSourceMapping(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration,
org.codehaus.plexus.compiler.Compiler compiler) |
protected abstract java.lang.String |
getTarget() |
protected org.apache.maven.toolchain.Toolchain |
getToolchain() |
private boolean |
hasNewFile(java.io.File classPathEntry,
java.util.Date buildStartTime) |
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 buid-started timestamp, then we catched a file which
got changed during this build.
|
private boolean |
isDigits(java.lang.String string) |
private boolean |
isSourceChanged(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration,
org.codehaus.plexus.compiler.Compiler compiler) |
protected boolean |
isTestCompile() |
protected abstract void |
preparePaths(java.util.Set<java.io.File> sourceFiles) |
private static java.util.List<java.lang.String> |
removeEmptyCompileSourceRoots(java.util.List<java.lang.String> compileSourceRootsList) |
private java.util.List<java.lang.String> |
resolveProcessorPathEntries() |
protected static final java.lang.String PS
static final java.lang.String DEFAULT_SOURCE
static final java.lang.String DEFAULT_TARGET
static final java.lang.String MODULE_INFO_TARGET
@Parameter(property="maven.compiler.failOnError", defaultValue="true") private boolean failOnError
@Parameter(property="maven.compiler.failOnWarning", defaultValue="false") private boolean failOnWarning
@Parameter(property="maven.compiler.debug", defaultValue="true") private boolean debug
true
to include debugging information in the compiled class files.@Parameter(property="maven.compiler.parameters", defaultValue="false") private boolean parameters
true
to generate metadata for reflection on method parameters.@Parameter(property="maven.compiler.verbose", defaultValue="false") private boolean verbose
true
to show messages about what the compiler is doing.@Parameter(property="maven.compiler.showDeprecation", defaultValue="false") private boolean showDeprecation
@Parameter(property="maven.compiler.optimize", defaultValue="false") private boolean optimize
true
to optimize the compiled code using the compiler's optimization methods.@Parameter(property="maven.compiler.showWarnings", defaultValue="false") private boolean showWarnings
true
to show compilation warnings.@Parameter(property="maven.compiler.source", defaultValue="1.5") protected java.lang.String source
@Parameter(property="maven.compiler.target", defaultValue="1.5") protected java.lang.String target
@Parameter(property="maven.compiler.release") protected java.lang.String release
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") private java.lang.String encoding
@Parameter(property="lastModGranularityMs", defaultValue="0") private int staleMillis
@Parameter(property="maven.compiler.compilerId", defaultValue="javac") private java.lang.String compilerId
@Parameter(property="maven.compiler.compilerVersion") private java.lang.String compilerVersion
fork
is set to true
.@Parameter(property="maven.compiler.fork", defaultValue="false") private boolean fork
false
it uses the built in compiler, while if true
it will use an executable.@Parameter(property="maven.compiler.meminitial") private java.lang.String meminitial
fork
is set to true
.@Parameter(property="maven.compiler.maxmem") private java.lang.String maxmem
fork
is set to true
.@Parameter(property="maven.compiler.executable") private java.lang.String executable
fork
is true
.@Parameter private java.lang.String 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.@Parameter private java.lang.String[] annotationProcessors
Names of annotation processors to run. Only applies to JDK 1.6+ If not set, the default annotation processors discovery process applies.
@Parameter private java.util.List<DependencyCoordinate> 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. Example:
<configuration> <annotationProcessorPaths> <path> <groupId>org.sample</groupId> <artifactId>sample-annotation-processor</artifactId> <version>1.2.3</version> </path> <!-- ... more ... --> </annotationProcessorPaths> </configuration>
@Parameter @Deprecated protected java.util.Map<java.lang.String,java.lang.String> compilerArguments
compilerArgs
instead.
Sets the arguments to be passed to the compiler (prepending a dash) if fork
is set to true
.
This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.
To pass -Xmaxerrs 1000 -Xlint -Xlint:-path -Averbose=true
you should include the following:
<compilerArguments> <Xmaxerrs>1000</Xmaxerrs> <Xlint/> <Xlint:-path/> <Averbose>true</Averbose> </compilerArguments>
@Parameter protected java.util.List<java.lang.String> compilerArgs
Sets the arguments to be passed to the compiler if fork
is set to true
.
Example:
<compilerArgs> <arg>-Xmaxerrs=1000</arg> <arg>-Xlint</arg> <arg>-J-Duser.language=en_us</arg> </compilerArgs>
@Parameter protected java.lang.String compilerArgument
Sets the unformatted single argument string to be passed to the compiler if fork
is set to
true
. To pass multiple arguments such as -Xmaxerrs 1000
(which are actually two
arguments) you have to use compilerArguments
.
This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.
@Parameter private java.lang.String outputFileName
@Parameter(property="maven.compiler.debuglevel") private java.lang.String debuglevel
-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.@Component private org.apache.maven.toolchain.ToolchainManager toolchainManager
@Parameter private java.util.Map<java.lang.String,java.lang.String> jdkToolchain
Specify the requirements for this jdk toolchain. This overrules the toolchain selected by the maven-toolchain-plugin.
note: requires at least Maven 3.3.1@Parameter(defaultValue="${basedir}", required=true, readonly=true) private java.io.File basedir
@Parameter(defaultValue="${project.build.directory}", required=true, readonly=true) private java.io.File buildDirectory
@Component private org.codehaus.plexus.compiler.manager.CompilerManager compilerManager
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
@Parameter(defaultValue="${reuseCreated}", property="maven.compiler.compilerReuseStrategy") private java.lang.String compilerReuseStrategy
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 build
alwaysNew
: a new Javacc class will be created for each compilation@Parameter(defaultValue="false", property="maven.compiler.skipMultiThreadWarning") private boolean skipMultiThreadWarning
@Parameter(defaultValue="false", property="maven.compiler.forceJavacCompilerUse") private boolean forceJavacCompilerUse
@Parameter(defaultValue="${mojoExecution}", readonly=true, required=true) private org.apache.maven.plugin.MojoExecution mojoExecution
@Parameter private java.util.List<java.lang.String> fileExtensions
.class
@Parameter(defaultValue="true", property="maven.compiler.useIncrementalCompilation") private boolean useIncrementalCompilation
@Component private org.apache.maven.repository.RepositorySystem repositorySystem
@Component private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager
@Component private org.apache.maven.artifact.resolver.ResolutionErrorHandler resolutionErrorHandler
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner(int staleMillis)
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner(java.lang.String inputFileEnding)
protected abstract java.util.List<java.lang.String> getClasspathElements()
protected abstract java.util.List<java.lang.String> getModulepathElements()
protected abstract java.util.Map<java.lang.String,org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor> getPathElements()
protected abstract java.util.List<java.lang.String> getCompileSourceRoots()
protected abstract void preparePaths(java.util.Set<java.io.File> sourceFiles)
protected abstract java.io.File getOutputDirectory()
protected abstract java.lang.String getSource()
protected abstract java.lang.String getTarget()
protected abstract java.lang.String getRelease()
protected abstract java.lang.String getCompilerArgument()
protected abstract java.util.Map<java.lang.String,java.lang.String> getCompilerArguments()
protected abstract java.io.File getGeneratedSourcesDirectory()
protected final org.apache.maven.project.MavenProject getProject()
public void execute() throws org.apache.maven.plugin.MojoExecutionException, CompilationFailureException
org.apache.maven.plugin.MojoExecutionException
CompilationFailureException
protected boolean isTestCompile()
protected org.codehaus.plexus.compiler.CompilerResult convertToCompilerResult(java.util.List<org.codehaus.plexus.compiler.CompilerError> compilerErrors)
private java.util.Set<java.io.File> getCompileSources(org.codehaus.plexus.compiler.Compiler compiler, org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration) throws org.apache.maven.plugin.MojoExecutionException, org.codehaus.plexus.compiler.CompilerException
org.apache.maven.plugin.MojoExecutionException
org.codehaus.plexus.compiler.CompilerException
private boolean isSourceChanged(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration, org.codehaus.plexus.compiler.Compiler compiler) throws org.codehaus.plexus.compiler.CompilerException, org.apache.maven.plugin.MojoExecutionException
compilerConfiguration
- compiler
- true
if at least a single source file is newer than it's class fileorg.codehaus.plexus.compiler.CompilerException
org.apache.maven.plugin.MojoExecutionException
protected int getRequestThreadCount()
protected java.util.Date getBuildStartTime()
private java.lang.String getMemoryValue(java.lang.String setting)
protected final org.apache.maven.toolchain.Toolchain getToolchain()
private boolean isDigits(java.lang.String string)
private java.util.Set<java.io.File> computeStaleSources(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration, org.codehaus.plexus.compiler.Compiler compiler, org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner scanner) throws org.apache.maven.plugin.MojoExecutionException, org.codehaus.plexus.compiler.CompilerException
org.apache.maven.plugin.MojoExecutionException
org.codehaus.plexus.compiler.CompilerException
private org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping getSourceMapping(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration, org.codehaus.plexus.compiler.Compiler compiler) throws org.codehaus.plexus.compiler.CompilerException, org.apache.maven.plugin.MojoExecutionException
org.codehaus.plexus.compiler.CompilerException
org.apache.maven.plugin.MojoExecutionException
private static java.util.List<java.lang.String> removeEmptyCompileSourceRoots(java.util.List<java.lang.String> compileSourceRootsList)
protected boolean isDependencyChanged()
true
if at least one single dependency has changed.private boolean hasNewFile(java.io.File classPathEntry, java.util.Date buildStartTime)
classPathEntry
- entry to checkbuildStartTime
- time build startprivate java.util.List<java.lang.String> resolveProcessorPathEntries() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException