Class AbstractCompilerMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugin.compiler.AbstractCompilerMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AbstractCompilerMojo,CompilerMojo,TestCompilerMojo
public abstract class AbstractCompilerMojo extends org.apache.maven.plugin.AbstractMojoTODO: At least one step could be optimized, currently the plugin will do two scans of all the source code if the compiler has to have the entire set of sources. This is currently the case for at least the C# compiler and most likely all the other .NET compilers too.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<DependencyCoordinate>annotationProcessorPathsClasspath elements to supply as annotation processor path.private java.lang.String[]annotationProcessorsNames of annotation processors to run.private org.apache.maven.artifact.handler.manager.ArtifactHandlerManagerartifactHandlerManagerArtifact handler manager.private java.io.FilebasedirThe directory to run the compiler from if fork is true.private java.io.FilebuildDirectoryThe target directory of the compiler if fork is true.protected java.util.List<java.lang.String>compilerArgsSets the arguments to be passed to the compiler ifforkis set totrue.protected java.lang.StringcompilerArgumentSets the unformatted single argument string to be passed to the compiler ifforkis set totrue.protected java.util.Map<java.lang.String,java.lang.String>compilerArgumentsDeprecated.usecompilerArgsinstead.private java.lang.StringcompilerIdThe compiler id of the compiler to use.private org.codehaus.plexus.compiler.manager.CompilerManagercompilerManagerPlexus compiler manager.private java.lang.StringcompilerReuseStrategyStrategy 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.private java.lang.StringcompilerVersionVersion of the compiler to use, ex.private booleandebugSet totrueto include debugging information in the compiled class files.private java.lang.StringdebuglevelKeyword list to be appended to the-gcommand-line switch.(package private) static java.lang.StringDEFAULT_SOURCE(package private) static java.lang.StringDEFAULT_TARGETprivate java.lang.StringencodingThe -encoding argument for the Java compiler.private java.lang.StringexecutableSets the executable of the compiler to use whenforkistrue.private booleanfailOnErrorIndicates whether the build will continue even if there are compilation errors.private booleanfailOnWarningIndicates whether the build will continue even if there are compilation warnings.private java.util.List<java.lang.String>fileExtensionsfile extensions to check timestamp for incremental build default contains only.classprivate booleanforceJavacCompilerUsecompiler 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 configurationprivate booleanforkAllows running the compiler in a separate process.private java.util.Map<java.lang.String,java.lang.String>jdkToolchainSpecify the requirements for this jdk toolchain.private java.lang.StringmaxmemSets the maximum size, in megabytes, of the memory allocation pool, ex.private java.lang.StringmeminitialInitial size, in megabytes, of the memory allocation pool, ex.(package private) static java.lang.StringMODULE_INFO_TARGETprivate org.apache.maven.plugin.MojoExecutionmojoExecutionprivate booleanoptimizeDeprecated.This property is a no-op injavac.private java.lang.StringoutputFileNameSets the name of the output file when compiling a set of sources to a single file.private booleanparametersSet totrueto generate metadata for reflection on method parameters.private java.lang.StringprocSets whether annotation processing is performed or not.private org.apache.maven.project.MavenProjectprojectThe current project instance.protected static java.lang.StringPSprotected java.lang.StringreleaseThe -release argument for the Java compiler, supported since Java9private org.apache.maven.repository.RepositorySystemrepositorySystemResolves the artifacts needed.private org.apache.maven.artifact.resolver.ResolutionErrorHandlerresolutionErrorHandlerThrows an exception on artifact resolution errors.private org.apache.maven.execution.MavenSessionsessionThe current build session instance.private booleanshowDeprecationSets whether to show source locations where deprecated APIs are used.private booleanshowWarningsSet totrueto show compilation warnings.private booleanskipMultiThreadWarningprotected java.lang.StringsourceThe -source argument for the Java compiler.private intstaleMillisSets the granularity in milliseconds of the last modification date for testing whether a source needs recompilation.protected java.lang.StringtargetThe -target argument for the Java compiler.private booleantargetOrReleaseSetprivate org.apache.maven.toolchain.ToolchainManagertoolchainManagerprivate booleanuseIncrementalCompilationto enable/disable incrementation compilation featureprivate booleanverboseSet totrueto show messages about what the compiler is doing.
-
Constructor Summary
Constructors Constructor Description AbstractCompilerMojo()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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.CompilerResultconvertToCompilerResult(java.util.List<org.codehaus.plexus.compiler.CompilerError> compilerErrors)voidexecute()protected java.util.DategetBuildStartTime()protected abstract java.util.List<java.lang.String>getClasspathElements()protected abstract java.lang.StringgetCompilerArgument()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.FilegetGeneratedSourcesDirectory()private java.lang.StringgetMavenCompilerPluginVersion()private java.lang.StringgetMemoryValue(java.lang.String setting)protected abstract java.util.List<java.lang.String>getModulepathElements()protected abstract java.io.FilegetOutputDirectory()protected abstract java.util.Map<java.lang.String,org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor>getPathElements()protected org.apache.maven.project.MavenProjectgetProject()protected abstract java.lang.StringgetRelease()protected intgetRequestThreadCount()try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependentprotected abstract java.lang.StringgetSource()protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScannergetSourceInclusionScanner(int staleMillis)protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScannergetSourceInclusionScanner(java.lang.String inputFileEnding)private org.codehaus.plexus.compiler.util.scan.mapping.SourceMappinggetSourceMapping(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration, org.codehaus.plexus.compiler.Compiler compiler)protected abstract java.lang.StringgetTarget()protected org.apache.maven.toolchain.ToolchaingetToolchain()private booleanhasNewFile(java.io.File classPathEntry, java.util.Date buildStartTime)protected booleanisDependencyChanged()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 booleanisDigits(java.lang.String string)private booleanisSourceChanged(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration, org.codehaus.plexus.compiler.Compiler compiler)protected booleanisTestCompile()protected abstract voidpreparePaths(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()voidsetRelease(java.lang.String release)voidsetTarget(java.lang.String target)private voidwriteConfig(org.apache.maven.shared.utils.logging.MessageBuilder mb)private voidwritePlugin(org.apache.maven.shared.utils.logging.MessageBuilder mb)
-
-
-
Field Detail
-
PS
protected static final java.lang.String PS
-
DEFAULT_SOURCE
static final java.lang.String DEFAULT_SOURCE
- See Also:
- Constant Field Values
-
DEFAULT_TARGET
static final java.lang.String DEFAULT_TARGET
- See Also:
- Constant Field Values
-
MODULE_INFO_TARGET
static final java.lang.String MODULE_INFO_TARGET
- See Also:
- Constant Field Values
-
failOnError
@Parameter(property="maven.compiler.failOnError", defaultValue="true") private 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") private boolean failOnWarningIndicates whether the build will continue even if there are compilation warnings.- Since:
- 3.6
-
debug
@Parameter(property="maven.compiler.debug", defaultValue="true") private boolean debugSet totrueto include debugging information in the compiled class files.
-
parameters
@Parameter(property="maven.compiler.parameters", defaultValue="false") private boolean parametersSet totrueto generate metadata for reflection on method parameters.- Since:
- 3.6.2
-
verbose
@Parameter(property="maven.compiler.verbose", defaultValue="false") private boolean verboseSet totrueto show messages about what the compiler is doing.
-
showDeprecation
@Parameter(property="maven.compiler.showDeprecation", defaultValue="false") private boolean showDeprecationSets whether to show source locations where deprecated APIs are used.
-
optimize
@Deprecated @Parameter(property="maven.compiler.optimize", defaultValue="false") private 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="false") private boolean showWarningsSet totrueto show compilation warnings.
-
source
@Parameter(property="maven.compiler.source", defaultValue="1.6") protected java.lang.String sourceThe -source argument for the Java compiler.
NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6
-
target
@Parameter(property="maven.compiler.target", defaultValue="1.6") protected java.lang.String targetThe -target argument for the Java compiler.
NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6
-
release
@Parameter(property="maven.compiler.release") protected java.lang.String release
The -release argument for the Java compiler, supported since Java9- Since:
- 3.6
-
encoding
@Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") private java.lang.String encodingThe -encoding argument for the Java compiler.- Since:
- 2.1
-
staleMillis
@Parameter(property="lastModGranularityMs", defaultValue="0") private int staleMillisSets the granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
-
compilerId
@Parameter(property="maven.compiler.compilerId", defaultValue="javac") private java.lang.String compilerIdThe compiler id of the compiler to use. See this guide for more information.
-
compilerVersion
@Parameter(property="maven.compiler.compilerVersion") private java.lang.String compilerVersion
Version of the compiler to use, ex. "1.3", "1.5", ifforkis set totrue.
-
fork
@Parameter(property="maven.compiler.fork", defaultValue="false") private boolean forkAllows running the compiler in a separate process. Iffalseit uses the built in compiler, while iftrueit will use an executable.
-
meminitial
@Parameter(property="maven.compiler.meminitial") private java.lang.String meminitial
Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" ifforkis set totrue.- Since:
- 2.0.1
-
maxmem
@Parameter(property="maven.compiler.maxmem") private java.lang.String maxmem
Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" ifforkis set totrue.- Since:
- 2.0.1
-
executable
@Parameter(property="maven.compiler.executable") private java.lang.String executable
Sets the executable of the compiler to use whenforkistrue.
-
proc
@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.
- Since:
- 2.2
-
annotationProcessors
@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.
- Since:
- 2.2
-
annotationProcessorPaths
@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>- Since:
- 3.5
-
compilerArguments
@Parameter @Deprecated protected java.util.Map<java.lang.String,java.lang.String> compilerArguments
Deprecated.usecompilerArgsinstead.Sets the arguments to be passed to the compiler (prepending a dash) if
forkis set totrue.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=trueyou should include the following:<compilerArguments> <Xmaxerrs>1000</Xmaxerrs> <Xlint/> <Xlint:-path/> <Averbose>true</Averbose> </compilerArguments>
- Since:
- 2.0.1
-
compilerArgs
@Parameter protected java.util.List<java.lang.String> compilerArgs
Sets the arguments to be passed to the compiler if
forkis set totrue. Example:<compilerArgs> <arg>-Xmaxerrs</arg> <arg>1000</arg> <arg>-Xlint</arg> <arg>-J-Duser.language=en_us</arg> </compilerArgs>
- Since:
- 3.1
-
compilerArgument
@Parameter protected java.lang.String compilerArgument
Sets the unformatted single argument string to be passed to the compiler if
forkis set totrue. To pass multiple arguments such as-Xmaxerrs 1000(which are actually two arguments) you have to usecompilerArguments.This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.
-
outputFileName
@Parameter private java.lang.String outputFileName
Sets the name of the output file when compiling a set of sources to a single file. expression="${project.build.finalName}"
-
debuglevel
@Parameter(property="maven.compiler.debuglevel") private java.lang.String debuglevel
Keyword list to be appended to the-gcommand-line switch. Legal values are none or a comma-separated list of the following keywords:lines,vars, andsource. 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.- Since:
- 2.1
-
toolchainManager
@Component private org.apache.maven.toolchain.ToolchainManager toolchainManager
-
jdkToolchain
@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- Since:
- 3.6
-
basedir
@Parameter(defaultValue="${basedir}", required=true, readonly=true) private java.io.File basedirThe directory to run the compiler from if fork is true.
-
buildDirectory
@Parameter(defaultValue="${project.build.directory}", required=true, readonly=true) private java.io.File buildDirectoryThe target directory of the compiler if fork is true.
-
compilerManager
@Component private org.codehaus.plexus.compiler.manager.CompilerManager compilerManager
Plexus compiler manager.
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession sessionThe current build session instance. This is used for toolchain manager API calls.
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject 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") private java.lang.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") private boolean skipMultiThreadWarning- Since:
- 2.5
-
forceJavacCompilerUse
@Parameter(defaultValue="false", property="maven.compiler.forceJavacCompilerUse") private boolean forceJavacCompilerUsecompiler 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- Since:
- 3.0
-
mojoExecution
@Parameter(defaultValue="${mojoExecution}", readonly=true, required=true) private org.apache.maven.plugin.MojoExecution mojoExecution- Since:
- 3.0 needed for storing the status for the incremental build support.
-
fileExtensions
@Parameter private java.util.List<java.lang.String> fileExtensions
file extensions to check timestamp for incremental build default contains only.class- Since:
- 3.1
-
useIncrementalCompilation
@Parameter(defaultValue="true", property="maven.compiler.useIncrementalCompilation") private boolean useIncrementalCompilationto enable/disable incrementation compilation feature- Since:
- 3.1
-
repositorySystem
@Component private org.apache.maven.repository.RepositorySystem repositorySystem
Resolves the artifacts needed.
-
artifactHandlerManager
@Component private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager
Artifact handler manager.
-
resolutionErrorHandler
@Component private org.apache.maven.artifact.resolver.ResolutionErrorHandler resolutionErrorHandler
Throws an exception on artifact resolution errors.
-
targetOrReleaseSet
private boolean targetOrReleaseSet
-
-
Method Detail
-
getSourceInclusionScanner
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner(int staleMillis)
-
getSourceInclusionScanner
protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner(java.lang.String inputFileEnding)
-
getClasspathElements
protected abstract java.util.List<java.lang.String> getClasspathElements()
-
getModulepathElements
protected abstract java.util.List<java.lang.String> getModulepathElements()
-
getPathElements
protected abstract java.util.Map<java.lang.String,org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor> getPathElements()
-
getCompileSourceRoots
protected abstract java.util.List<java.lang.String> getCompileSourceRoots()
-
preparePaths
protected abstract void preparePaths(java.util.Set<java.io.File> sourceFiles)
-
getOutputDirectory
protected abstract java.io.File getOutputDirectory()
-
getSource
protected abstract java.lang.String getSource()
-
getTarget
protected abstract java.lang.String getTarget()
-
getRelease
protected abstract java.lang.String getRelease()
-
getCompilerArgument
protected abstract java.lang.String getCompilerArgument()
-
getCompilerArguments
protected abstract java.util.Map<java.lang.String,java.lang.String> getCompilerArguments()
-
getGeneratedSourcesDirectory
protected abstract java.io.File getGeneratedSourcesDirectory()
-
getProject
protected final org.apache.maven.project.MavenProject getProject()
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, CompilationFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionCompilationFailureException
-
isTestCompile
protected boolean isTestCompile()
-
convertToCompilerResult
protected org.codehaus.plexus.compiler.CompilerResult convertToCompilerResult(java.util.List<org.codehaus.plexus.compiler.CompilerError> compilerErrors)
-
getCompileSources
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- Returns:
- all source files for the compiler
- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.codehaus.plexus.compiler.CompilerException
-
isSourceChanged
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- Parameters:
compilerConfiguration-compiler-- Returns:
trueif at least a single source file is newer than it's class file- Throws:
org.codehaus.plexus.compiler.CompilerExceptionorg.apache.maven.plugin.MojoExecutionException
-
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
protected java.util.Date getBuildStartTime()
-
getMemoryValue
private java.lang.String getMemoryValue(java.lang.String setting)
-
getToolchain
protected final org.apache.maven.toolchain.Toolchain getToolchain()
-
isDigits
private boolean isDigits(java.lang.String string)
-
computeStaleSources
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- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.codehaus.plexus.compiler.CompilerException
-
getSourceMapping
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- Throws:
org.codehaus.plexus.compiler.CompilerExceptionorg.apache.maven.plugin.MojoExecutionException
-
removeEmptyCompileSourceRoots
private static java.util.List<java.lang.String> removeEmptyCompileSourceRoots(java.util.List<java.lang.String> compileSourceRootsList)
-
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 buid-started timestamp, then we catched a file which got changed during this build.- Returns:
trueif at least one single dependency has changed.
-
hasNewFile
private boolean hasNewFile(java.io.File classPathEntry, java.util.Date buildStartTime)- Parameters:
classPathEntry- entry to checkbuildStartTime- time build start- Returns:
- if any changes occurred
-
resolveProcessorPathEntries
private java.util.List<java.lang.String> resolveProcessorPathEntries() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
writePlugin
private void writePlugin(org.apache.maven.shared.utils.logging.MessageBuilder mb)
-
writeConfig
private void writeConfig(org.apache.maven.shared.utils.logging.MessageBuilder mb)
-
getMavenCompilerPluginVersion
private java.lang.String getMavenCompilerPluginVersion()
-
setTarget
public void setTarget(java.lang.String target)
-
setRelease
public void setRelease(java.lang.String release)
-
-