Package org.apache.maven.plugin.compiler
Class CompilerMojo
java.lang.Object
org.apache.maven.plugin.compiler.AbstractCompilerMojo
org.apache.maven.plugin.compiler.CompilerMojo
- All Implemented Interfaces:
org.apache.maven.api.plugin.Mojo
@Mojo(name="compile",
defaultPhase="compile")
public class CompilerMojo
extends AbstractCompilerMojo
Compiles application sources.
Each instance shall be used only once, then discarded.
- Since:
- 2.0
- Author:
- Jason van Zyl, Martin Desruisseaux
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
The file where to dump the command-line when debug is activated or when the compilation failed.A set of exclusion filters for the compiler.protected Path
Specify where to place generated source files created by annotation processing.A set of inclusion filters for the compiler.A set of exclusion filters for the incremental calculation.protected boolean
Deprecated.protected Path
The directory for compiled classes.protected org.apache.maven.api.ProducedArtifact
Projects main artifact.protected boolean
Set this totrue
to bypass compilation of main sources.Fields inherited from class org.apache.maven.plugin.compiler.AbstractCompilerMojo
annotationProcessorPaths, annotationProcessorPathsUseDepMgmt, annotationProcessors, artifactManager, basedir, compilerArgs, compilerArgument, compilerId, compilerReuseStrategy, compilerVersion, compileSourceRoots, createMissingPackageInfoClass, debug, debuglevel, enablePreview, encoding, executable, failOnError, failOnWarning, fileExtensions, forceJavacCompilerUse, forceLegacyJavacApi, fork, implicit, incrementalCompilation, jdkToolchain, logger, maxmem, meminitial, messageBuilderFactory, moduleVersion, mojoStatusPath, optimize, outputFileName, outputTimestamp, parameters, proc, project, projectManager, release, session, showCompilationChanges, showDeprecation, showWarnings, skipMultiThreadWarning, source, staleMillis, target, toolchainManager, useIncrementalCompilation, verbose
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateExecutor
(DiagnosticListener<? super JavaFileObject> listener) Creates a new task for compiling the main classes.void
execute()
Runs the Java compiler on the main source code.protected String
Returns the file where to dump the command-line when debug is activated or when the compilation failed.Returns the exclusion filters for the compiler, or an empty set if none.protected Path
Returns the path where to place generated source files created by annotation processing on the main classes.Returns the inclusion filters for the compiler, or an empty set for all Java source files.Returns the exclusion filters for the incremental calculation, or an empty set if none.protected Path
Returns the destination directory for main class files.parseParameters
(OptionChecker compiler) Parses the parameters declared in the MOJO.Methods inherited from class org.apache.maven.plugin.compiler.AbstractCompilerMojo
compiler, getRelease, getSource, getTarget
-
Field Details
-
skipMain
@Parameter(property="maven.main.skip") protected boolean skipMainSet this totrue
to bypass compilation of main sources. Its use is not recommended, but quite convenient on occasion. -
generatedSourcesDirectory
@Parameter(defaultValue="${project.build.directory}/generated-sources/annotations") protected Path generatedSourcesDirectorySpecify where to place generated source files created by annotation processing.- Since:
- 2.2
-
includes
A set of inclusion filters for the compiler. -
excludes
A set of exclusion filters for the compiler. -
incrementalExcludes
A set of exclusion filters for the incremental calculation. Updated source files, if excluded by this filter, will not cause the project to be rebuilt.Limitation
In the current implementation, those exclusion filters are applied for added or removed files, but not yet for removed files.- Since:
- 3.11
-
outputDirectory
@Parameter(defaultValue="${project.build.outputDirectory}", required=true, readonly=true) protected Path outputDirectoryThe directory for compiled classes.- See Also:
-
projectArtifact
@Parameter(defaultValue="${project.mainArtifact}", readonly=true, required=true) protected org.apache.maven.api.ProducedArtifact projectArtifactProjects main artifact. -
multiReleaseOutput
Deprecated.Replaced by specifying the<targetVersion>
value inside a<source>
element.When set totrue
, the classes will be placed inMETA-INF/versions/${release}
.Note: A jar is only a multi-release jar if
META-INF/MANIFEST.MF
containsMulti-Release: true
. You need to set this by configuring the maven-jar-plugin. This implies that you cannot test a multi-release jar using theoutputDirectory
.- Since:
- 3.7.1
-
debugFileName
The file where to dump the command-line when debug is activated 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.By default, this debug file is written only if the compilation of main code failed. The writing of the debug files can be forced by setting the
AbstractCompilerMojo.verbose
flag totrue
or by specifying the--verbose
option to Maven on the command-line.- Since:
- 3.10.0
-
-
Constructor Details
-
CompilerMojo
public CompilerMojo()Creates a new compiler MOJO for the main code.
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.api.plugin.MojoExceptionRuns the Java compiler on the main source code. IfskipMain
istrue
, then this method logs a message and does nothing else. Otherwise, this method executes the steps described in the method of the parent class.- Specified by:
execute
in interfaceorg.apache.maven.api.plugin.Mojo
- Overrides:
execute
in classAbstractCompilerMojo
- Throws:
org.apache.maven.api.plugin.MojoException
- if the compiler cannot be run.
-
parseParameters
Parses the parameters declared in the MOJO.- Overrides:
parseParameters
in classAbstractCompilerMojo
- Parameters:
compiler
- the tools to use for verifying the validity of options- Returns:
- the options after validation
-
getGeneratedSourcesDirectory
Returns the path where to place generated source files created by annotation processing on the main classes.- Specified by:
getGeneratedSourcesDirectory
in classAbstractCompilerMojo
- Returns:
- the path where to place generated source files created by annotation processing on the main classes
-
getIncludes
Returns the inclusion filters for the compiler, or an empty set for all Java source files.- Specified by:
getIncludes
in classAbstractCompilerMojo
- Returns:
- the inclusion filters for the compiler, or an empty set for all Java source files
-
getExcludes
Returns the exclusion filters for the compiler, or an empty set if none.- Specified by:
getExcludes
in classAbstractCompilerMojo
- Returns:
- the exclusion filters for the compiler, or an empty set if none
-
getIncrementalExcludes
Returns the exclusion filters for the incremental calculation, or an empty set if none.- Specified by:
getIncrementalExcludes
in classAbstractCompilerMojo
- Returns:
- the exclusion filters for the incremental calculation, or an empty set if none
- See Also:
-
getOutputDirectory
Returns the destination directory for main class files. IfmultiReleaseOutput
is true (deprecated), the output will be in aMETA-INF/versions
subdirectory.- Specified by:
getOutputDirectory
in classAbstractCompilerMojo
- Returns:
- the destination directory for main class files
-
getDebugFileName
Returns the file where to dump the command-line when debug is activated or when the compilation failed.- Specified by:
getDebugFileName
in classAbstractCompilerMojo
- Returns:
- the file where to dump the command-line when debug is activated or when the compilation failed
- See Also:
-
createExecutor
public ToolExecutor createExecutor(DiagnosticListener<? super JavaFileObject> listener) throws IOException Creates a new task for compiling the main classes.- Overrides:
createExecutor
in classAbstractCompilerMojo
- Parameters:
listener
- where to send compilation warnings, ornull
for the Maven logger- Returns:
- the task to execute for compiling the main code 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 directories
-
<targetVersion>
value inside a<source>
element.