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 TypeFieldDescriptionThe source directories containing the sources to be compiled.protected StringThe 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 PathSpecify 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 booleanDeprecated.Replaced by specifying the release version together with the source directory.protected PathThe directory for compiled classes.protected org.apache.maven.api.ProducedArtifactProjects main artifact.protected booleanSet this totrueto 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, 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 TypeMethodDescriptionprotected OptionsacceptParameters(OptionChecker compiler) Parses the parameters declared in the MOJO.protected voidaddImplicitDependencies(Map<org.apache.maven.api.PathType, List<Path>> addTo, boolean hasModuleDeclaration) Deprecated.For compatibility with the previous way to build multi-releases JAR file.voidexecute()Runs the Java compiler on the main source code.Returns the root directories of Java source files to compile.protected StringReturns 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 PathReturns 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 PathReturns the destination directory for main class files.Methods inherited from class org.apache.maven.plugin.compiler.AbstractCompilerMojo
addModuleOptions, getRelease, getSource, getTarget
-
Field Details
-
skipMain
@Parameter(property="maven.main.skip") protected boolean skipMainSet this totrueto bypass compilation of main sources. Its use is not recommended, but quite convenient on occasion. -
compileSourceRoots
The source directories containing the sources to be compiled. Ifnullor empty, the directory will be obtained from the project manager. -
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. -
projectArtifact
@Parameter(defaultValue="${project.mainArtifact}", readonly=true, required=true) protected org.apache.maven.api.ProducedArtifact projectArtifactProjects main artifact. -
multiReleaseOutput
Deprecated.Replaced by specifying the release version together with the source directory.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.MFcontainsMulti-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.- Since:
- 3.10.0
-
-
Constructor Details
-
CompilerMojo
public CompilerMojo()Creates a new compiler MOJO.
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.api.plugin.MojoExceptionRuns the Java compiler on the main source code.- Specified by:
executein interfaceorg.apache.maven.api.plugin.Mojo- Overrides:
executein classAbstractCompilerMojo- Throws:
org.apache.maven.api.plugin.MojoException- if the compiler cannot be run.
-
acceptParameters
Parses the parameters declared in the MOJO.- Overrides:
acceptParametersin classAbstractCompilerMojo- Parameters:
compiler- the tools to use for verifying the validity of options- Returns:
- the options after validation
-
getCompileSourceRoots
Returns the root directories of Java source files to compile.. It can be a parameter specified to the compiler plugin, or otherwise the value provided by the project manager.- Specified by:
getCompileSourceRootsin classAbstractCompilerMojo- Returns:
- the root directories of Java source files to compile
-
getGeneratedSourcesDirectory
Returns the path where to place generated source files created by annotation processing on the main classes..- Specified by:
getGeneratedSourcesDirectoryin 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:
getIncludesin 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:
getExcludesin 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:
getIncrementalExcludesin 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.. IfmultiReleaseOutputis true (deprecated), the output will be in aMETA-INF/versionssubdirectory.- Specified by:
getOutputDirectoryin 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:
getDebugFileNamein classAbstractCompilerMojo- Returns:
- the file where to dump the command-line when debug is activated or when the compilation failed
-
addImplicitDependencies
@Deprecated(since="4.0.0") protected void addImplicitDependencies(Map<org.apache.maven.api.PathType, List<Path>> addTo, boolean hasModuleDeclaration) throws IOExceptionDeprecated.For compatibility with the previous way to build multi-releases JAR file.If compiling a multi-release JAR in the old deprecated way, add the previous versions to the path.- Overrides:
addImplicitDependenciesin classAbstractCompilerMojo- Parameters:
addTo- where to add dependencieshasModuleDeclaration- whether the main sources have or should have amodule-infofile- Throws:
IOException- if this method needs to walk through directories and that operation failed
-