Class AbstractCompilerMojo

java.lang.Object
org.apache.maven.plugin.compiler.AbstractCompilerMojo
All Implemented Interfaces:
org.apache.maven.api.plugin.Mojo
Direct Known Subclasses:
CompilerMojo, TestCompilerMojo

public abstract class AbstractCompilerMojo extends Object implements org.apache.maven.api.plugin.Mojo
Base class of Mojos compiling Java source code. This plugin uses the JavaCompiler interface from JDK 6+. Each instance shall be used only once, then discarded.
Since:
2.0
Author:
Trygve Laugstøl, Martin Desruisseaux
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Deprecated.
    Replaced by ordinary dependencies with <type> element set to proc, classpath-proc or modular-proc.
    protected boolean
    Whether to use the Maven dependency management section when resolving transitive dependencies of annotation processor paths.
    protected String[]
    Class names of annotation processors to run.
    protected org.apache.maven.api.services.ArtifactManager
     
    protected Path
    The directory to run the compiler from if fork is true.
    protected List<String>
    Additional arguments to be passed verbatim to the Java compiler.
    protected String
    Deprecated.
    Use compilerArgs instead.
    protected String
    Identifier of the compiler to use.
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
    Not supported anymore.
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
    This parameter is no longer used by the underlying compilers.
    protected boolean
    Whether to generate package-info.class even when empty.
    protected boolean
    Whether to include debugging information in the compiled class files.
    protected String
    Keyword list to be appended to the -g command-line switch.
    protected boolean
    Whether to enable preview language features of the java compiler.
    protected String
    The -encoding argument for the Java compiler.
    protected String
    Executable of the compiler to use when fork is true.
    protected boolean
    Whether the build will stop if there are compilation errors.
    protected boolean
    Whether the build will stop if there are compilation warnings.
    protected List<String>
    File extensions to check timestamp for incremental build.
    protected Boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Ignored because java.lang.Compiler has been deprecated and removed from the JDK.
    protected Boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Ignored because the compiler plugin now always use the javax.tools API.
    protected boolean
    Allows running the compiler in a separate process.
    protected String
    Whether to generate class files for implicitly referenced files.
    protected String
    The algorithm to use for selecting which files to compile.
    protected Map<String,String>
    Requirements for this JDK toolchain for using a different javac than the one of the JDK used by Maven.
    protected org.apache.maven.api.plugin.Log
    The logger for reporting information or warnings to the user.
    protected String
    Maximum size, in megabytes, of the memory allocation pool if fork is set to true.
    protected String
    Initial size, in megabytes, of the memory allocation pool if fork is set to true.
    protected org.apache.maven.api.services.MessageBuilderFactory
     
    protected String
    The --module-version argument for the Java compiler.
    protected Path
    Path to a file where to cache information about the last incremental build.
    protected Boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    This property is ignored.
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
    Bundling many class files into a single file should be done by other plugins.
    protected String
    Deprecated, for removal: This API element is subject to removal in a future version.
    Not used by the compiler plugin since it does not generate archive.
    protected boolean
    Whether to generate metadata for reflection on method parameters.
    protected String
    Whether annotation processing is performed or not.
    protected org.apache.maven.api.Project
    The current project instance.
    protected org.apache.maven.api.services.ProjectManager
     
    protected String
    The --release argument for the Java compiler.
    protected org.apache.maven.api.Session
    The current build session instance.
    protected boolean
    Whether to provide more details about why a module is rebuilt.
    protected boolean
    Whether to show source locations where deprecated APIs are used.
    protected boolean
    Whether to show compilation warnings.
    protected Boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Deprecated as a consequence of compilerReuseStrategy deprecation.
    protected String
    The --source argument for the Java compiler.
    protected int
    The granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
    protected String
    The --target argument for the Java compiler.
    protected org.apache.maven.api.services.ToolchainManager
     
    protected Boolean
    Deprecated.
    protected boolean
    Whether to show messages about what the compiler is doing.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractCompilerMojo(boolean isTestCompile)
    Creates a new MOJO.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Options
    Parses the parameters declared in the MOJO.
    protected void
    addImplicitDependencies(Map<org.apache.maven.api.PathType,List<Path>> addTo, boolean hasModuleDeclaration)
    Adds dependencies others than the ones declared in POM file.
    protected void
    addModuleOptions(org.apache.maven.api.services.DependencyResolverResult dependencies, Options addTo)
    Generates options for handling the given dependencies.
    void
    Runs the Java compiler.
    protected abstract List<Path>
    Returns the root directories of Java source files to compile.
    protected abstract String
    Returns the file where to dump the command-line when debug logging is enabled or when the compilation failed.
    protected abstract Set<String>
    Returns the exclusion filters for the compiler, or an empty list if none.
    protected abstract Path
    Returns the path where to place generated source files created by annotation processing.
    protected abstract Set<String>
    Returns the inclusion filters for the compiler, or an empty list for all Java source files.
    protected abstract Set<String>
    Returns the exclusion filters for the incremental calculation.
    protected abstract Path
    Returns the destination directory (or class output directory) for class files.
    protected String
    Returns the --release argument for the Java compiler.
    protected String
    Returns the --source argument for the Java compiler.
    protected String
    Returns the --target argument for the Java compiler.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • moduleVersion

      @Parameter(property="maven.compiler.moduleVersion", defaultValue="${project.version}") protected String moduleVersion
      The --module-version argument for the Java compiler. This is ignored if not applicable, e.g., in non-modular projects.
      Since:
      4.0.0
      See Also:
    • encoding

      @Parameter(property="encoding", defaultValue="${project.build.sourceEncoding}") protected String encoding
      The -encoding argument for the Java compiler.
      Since:
      2.1
      See Also:
    • source

      @Parameter(property="maven.compiler.source") protected String source
      The --source argument for the Java compiler.

      Notes:

      • 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.
      • Since 4.0.0-beta-2 the default value has been removed. As of Java 9, the release parameter is preferred.
      See Also:
    • target

      @Parameter(property="maven.compiler.target") protected String target
      The --target argument for the Java compiler.

      Notes:

      • 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.
      • Since 4.0.0-beta-2 the default value has been removed. As of Java 9, the release parameter is preferred.
      See Also:
    • release

      @Parameter(property="maven.compiler.release") protected String release
      The --release argument for the Java compiler. If omitted, then the compiler will generate bytecodes for the Java version running the compiler.
      Since:
      3.6
      See Also:
    • enablePreview

      @Parameter(property="maven.compiler.enablePreview", defaultValue="false") protected boolean enablePreview
      Whether to enable preview language features of the java compiler. If true, then the --enable-preview option will be added to compiler arguments.
      Since:
      3.10.1
      See Also:
    • compilerArgs

      @Parameter protected List<String> compilerArgs
      Additional arguments to be passed verbatim to the Java compiler. This parameter can be used when the Maven compiler plugin does not provide a parameter for a Java compiler option. It may happen, for example, for new or preview Java features which are not yet handled by this compiler plugin.

      If an option has a value, the option and the value shall be specified in two separated <arg> elements. For example, the -Xmaxerrs 1000 option (for setting the maximal number of errors to 1000) can be specified as below (together with other options):

      
       <compilerArgs>
         <arg>-Xlint</arg>
         <arg>-Xmaxerrs</arg>
         <arg>1000</arg>
         <arg>J-Duser.language=en_us</arg>
       </compilerArgs>
      Note that -J options should be specified only if fork is set to true. Other options can be specified regardless the fork value. The compiler plugin does not verify whether the arguments given through this parameter are valid. For this reason, the other parameters provided by the compiler plugin should be preferred when they exist, because the plugin checks whether the corresponding options are supported.
      Since:
      3.1
      See Also:
    • compilerArgument

      @Parameter @Deprecated(since="4.0.0") protected String compilerArgument
      Deprecated.
      Use compilerArgs instead.
      The single argument string to be passed to the compiler. To pass multiple arguments such as -Xmaxerrs 1000 (which are actually two arguments), compilerArgs is preferred.

      Note that -J options should be specified only if fork is set to true.

      See Also:
    • proc

      @Parameter(property="maven.compiler.proc") protected String proc
      Whether annotation processing is performed or not. If not set, both compilation and annotation processing are performed at the same time. If set, the value will be appended to the -proc: compiler option. Standard values are:
      • none – no annotation processing is performed.
      • only – only annotation processing is done, no compilation.
      • full – annotation processing and compilation are done.
      Prior Java 21, full was the default. Starting with JDK 21, this option must be set explicitly.
      Since:
      2.2
      See Also:
    • annotationProcessors

      @Parameter protected String[] annotationProcessors
      Class names of annotation processors to run. If not set, the default annotation processors discovery process applies. If set, the value will be appended to the -processor compiler option.
      Since:
      2.2
      See Also:
    • annotationProcessorPaths

      @Parameter @Deprecated(since="4.0.0") protected List<DependencyCoordinate> annotationProcessorPaths
      Deprecated.
      Replaced by ordinary dependencies with <type> element set to proc, classpath-proc or modular-proc.
      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 annotationProcessorPathsUseDepMgmt
      Whether 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
    • createMissingPackageInfoClass

      @Parameter(property="maven.compiler.createMissingPackageInfoClass", defaultValue="false") protected boolean createMissingPackageInfoClass
      Whether to generate package-info.class even when empty. By default, package info source files that only contain javadoc and no annotation on the package can lead to no class file being generated by the compiler. It may cause a file miss on build systems that check for file existence in order to decide what to recompile.

      If true, the -Xpkginfo:always compiler option is added if the compiler supports that extra option. If the extra option is not supported, then a warning is logged and no option is added to the compiler arguments.

      Since:
      3.10
      See Also:
    • implicit

      @Parameter(property="maven.compiler.implicit") protected String implicit
      Whether to generate class files for implicitly referenced files. If set, the value will be appended to the -implicit: compiler option. Standard values are:
      • class – automatically generates class files.
      • none – suppresses class file generation.
      Since:
      3.10.2
      See Also:
    • parameters

      @Parameter(property="maven.compiler.parameters", defaultValue="false") protected boolean parameters
      Whether to generate metadata for reflection on method parameters. If true, the -parameters option will be added to compiler arguments.
      Since:
      3.6.2
      See Also:
    • debug

      @Parameter(property="maven.compiler.debug", defaultValue="true") protected boolean debug
      Whether to include debugging information in the compiled class files. The amount of debugging information to include is specified by the debuglevel parameter. If this debug flag is true, then the -g option may be added to compiler arguments with a value determined by the debuglevel argument. If this debug flag is false, then the -g:none option will be added to the compiler arguments.
      See Also:
    • debuglevel

      @Parameter(property="maven.compiler.debuglevel") protected String debuglevel
      Keyword list to be appended to the -g command-line switch. Legal values are a comma-separated list of the following keywords: lines, vars, source and all. If debug level is not specified, then the -g option will not by added, which means that the default debugging information will be generated (typically lines and source but not vars). If debug is turned off, this attribute will be ignored.
      Since:
      2.1
      See Also:
    • optimize

      @Deprecated(forRemoval=true) @Parameter(property="maven.compiler.optimize") protected Boolean optimize
      Deprecated, for removal: This API element is subject to removal in a future version.
      This property is ignored.
      Whether to optimize the compiled code using the compiler's optimization methods.
    • verbose

      @Parameter(property="maven.compiler.verbose", defaultValue="false") protected boolean verbose
      Whether to show messages about what the compiler is doing. If true, then the -verbose option will be added to compiler arguments.
      See Also:
    • showCompilationChanges

      @Parameter(property="maven.compiler.showCompilationChanges", defaultValue="false") protected boolean showCompilationChanges
      Whether to provide more details about why a module is rebuilt. This is used only if incrementalCompilation is "inputTreeChanges".
      See Also:
    • showDeprecation

      @Parameter(property="maven.compiler.showDeprecation", defaultValue="false") protected boolean showDeprecation
      Whether to show source locations where deprecated APIs are used. If true, then the -deprecation option will be added to compiler arguments. That option is itself a shorthand for -Xlint:deprecation.
      See Also:
    • showWarnings

      @Parameter(property="maven.compiler.showWarnings", defaultValue="true") protected boolean showWarnings
      Whether to show compilation warnings. If false, then the -nowarn option will be added to compiler arguments. That option is itself a shorthand for -Xlint:none.
      See Also:
    • failOnWarning

      @Parameter(property="maven.compiler.failOnWarning", defaultValue="false") protected boolean failOnWarning
      Whether the build will stop if there are compilation warnings. If true, then the -Werror option will be added to compiler arguments.
      Since:
      3.6
      See Also:
    • failOnError

      @Parameter(property="maven.compiler.failOnError", defaultValue="true") protected boolean failOnError
      Whether the build will stop if there are compilation errors.
      Since:
      2.0.2
      See Also:
    • outputFileName

      @Parameter @Deprecated(since="4.0.0", forRemoval=true) protected String outputFileName
      Deprecated, for removal: This API element is subject to removal in a future version.
      Bundling many class files into a single file should be done by other plugins.
      Sets the name of the output file when compiling a set of sources to a single file.

      expression="${project.build.finalName}"

    • outputTimestamp

      @Deprecated(since="4.0.0", forRemoval=true) @Parameter(defaultValue="${project.build.outputTimestamp}") protected String outputTimestamp
      Deprecated, for removal: This API element is subject to removal in a future version.
      Not used by the compiler plugin since it does not generate archive.
      Timestamp for reproducible output archive entries. It can be either formatted as ISO 8601 yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
      Since:
      3.12.0
    • incrementalCompilation

      @Parameter(defaultValue="options,dependencies,sources") protected String incrementalCompilation
      The algorithm to use for selecting which files to compile. Values can be dependencies, sources, classes, additions, modules or none.

      options: recompile all source files if the compiler options changed. Changes are detected on a best-effort basis only.

      dependencies: recompile all source files if at least one dependency (JAR file) changed since the last build. This check is based on the last modification times of JAR files.

      sources: recompile source files modified since the last build. In addition, if a source file has been deleted, then all source files are recompiled. This check is based on the modification times of source files rather than the modification times of the *.class files.

      classes: recompile source files (*.java) associated to no output file (*.class) or associated to an output file older than the source. This algorithm does not check if a source file has been removed, potentially leaving non-recompiled classes with references to classes that no longer exist.

      The sources and classes values are partially redundant, doing the same work in different ways. It is usually not necessary to specify those two values.

      additions: recompile all source files when the addition of a new file is detected. This aspect should be used together with sources or classes. When used with classes, it provides a way to detect class renaming (this is not needed with sources).

      modules: recompile modules and let the compiler decides which individual files to recompile. The compiler plugin does not enumerate the source files to recompile (actually, it does not scan at all the source directories). Instead, it only specifies the module to recompile using the --module option. The Java compiler will scan the source directories itself and compile only those source files that are newer than the corresponding files in the output directory.

      none: the compiler plugin unconditionally specifies all sources to the Java compiler. This option is mutually exclusive with all other incremental compilation options.

      Limitations

      In all cases, the current compiler-plugin does not detect structural changes other than file addition or removal. For example, the plugin does not detect whether a method has been removed in a class.
      Since:
      4.0.0
      See Also:
    • useIncrementalCompilation

      @Deprecated(since="4.0.0") @Parameter(property="maven.compiler.useIncrementalCompilation") protected Boolean useIncrementalCompilation
      Deprecated.
      Replaced by incrementalCompilation. A value of true in this old property is equivalent to "dependencies,sources,additions" in the new property, and a value of false is equivalent to "classes".
      Whether to enable/disable incremental compilation feature.
      Since:
      3.1
    • fileExtensions

      @Parameter protected List<String> fileExtensions
      File extensions to check timestamp for incremental build. Default contains only class and jar. TODO: Rename with a name making clearer that this parameter is about incremental build.
      Since:
      3.1
      See Also:
    • staleMillis

      @Parameter(property="lastModGranularityMs", defaultValue="0") protected int staleMillis
      The granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
      See Also:
    • fork

      @Parameter(property="maven.compiler.fork", defaultValue="false") protected boolean fork
      Allows running the compiler in a separate process. If false, the plugin uses the built-in compiler, while if true it will use an executable.
      See Also:
    • jdkToolchain

      @Parameter protected Map<String,String> jdkToolchain
      Requirements for this JDK toolchain for using a different javac than the one of the JDK used by Maven. This overrules the toolchain selected by the maven-toolchain-plugin. See Guide to Toolchains for more info.
       <configuration>
         <jdkToolchain>
           <version>11</version>
         </jdkToolchain>
         ...
       </configuration>
      
       <configuration>
         <jdkToolchain>
           <version>1.8</version>
           <vendor>zulu</vendor>
         </jdkToolchain>
         ...
       </configuration>
       
      Since:
      3.6
      See Also:
    • compilerId

      @Parameter(property="maven.compiler.compilerId") protected String compilerId
      Identifier of the compiler to use. This identifier shall match the identifier of a compiler known to the JDK tool chain, or the name of a JavaCompiler instance registered as a service findable by ServiceLoader. See this guide for more information. If unspecified, then the system Java compiler is used. The identifier of the system Java compiler is usually javac.
      See Also:
    • compilerVersion

      @Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.compilerVersion") protected String compilerVersion
      Deprecated, for removal: This API element is subject to removal in a future version.
      This parameter is no longer used by the underlying compilers.
      Version of the compiler to use if fork is set to true. Examples! "1.3", "1.5".
      See Also:
    • forceLegacyJavacApi

      @Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.forceLegacyJavacApi") protected Boolean forceLegacyJavacApi
      Deprecated, for removal: This API element is subject to removal in a future version.
      Ignored because the compiler plugin now always use the javax.tools API.
      Whether to use the legacy com.sun.tools.javac API instead of javax.tools API.
      Since:
      3.13
      See Also:
    • forceJavacCompilerUse

      @Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.forceJavacCompilerUse") protected Boolean forceJavacCompilerUse
      Deprecated, for removal: This API element is subject to removal in a future version.
      Ignored because java.lang.Compiler has been deprecated and removed from the JDK.
      Whether to use legacy compiler API.
      Since:
      3.0
    • compilerReuseStrategy

      @Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.compilerReuseStrategy") protected String compilerReuseStrategy
      Deprecated, for removal: This API element is subject to removal in a future version.
      Not supported anymore. The reuse of JavaFileManager instance is plugin implementation details.
      Strategy to re use javacc class created. Legal values are:
      • 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.
      Since:
      2.5
    • skipMultiThreadWarning

      @Deprecated(since="4.0.0", forRemoval=true) @Parameter(property="maven.compiler.skipMultiThreadWarning") protected Boolean skipMultiThreadWarning
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated as a consequence of compilerReuseStrategy deprecation.
      Since:
      2.5
    • executable

      @Parameter(property="maven.compiler.executable") protected String executable
      Executable of the compiler to use when fork is true. If this parameter is specified, then the jdkToolchain is ignored.
      See Also:
    • meminitial

      @Parameter(property="maven.compiler.meminitial") protected String meminitial
      Initial size, in megabytes, of the memory allocation pool if fork is set to true. Examples: "64", "64M". Suffixes "k" (for kilobytes) and "G" (for gigabytes) are also accepted. If no suffix is provided, "M" is assumed.
      Since:
      2.0.1
      See Also:
    • maxmem

      @Parameter(property="maven.compiler.maxmem") protected String maxmem
      Maximum size, in megabytes, of the memory allocation pool if fork is set to true. Examples: "128", "128M". Suffixes "k" (for kilobytes) and "G" (for gigabytes) are also accepted. If no suffix is provided, "M" is assumed.
      Since:
      2.0.1
      See Also:
    • basedir

      @Parameter(defaultValue="${project.basedir}", required=true, readonly=true) protected Path basedir
      The directory to run the compiler from if fork is true.
    • mojoStatusPath

      @Parameter(defaultValue="${project.build.directory}/maven-status/${mojo.plugin.descriptor.artifactId}/${mojo.executionId}.cache", required=true, readonly=true) protected Path mojoStatusPath
      Path to a file where to cache information about the last incremental build. This is used when "incremental" builds are enabled for detecting additions or removals of source files, or changes in plugin configuration. This file should be in the output directory and can be deleted at any time
    • session

      @Inject protected org.apache.maven.api.Session session
      The current build session instance.
    • project

      @Inject protected org.apache.maven.api.Project project
      The current project instance.
    • 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
      The logger for reporting information or warnings to the user. Currently, this is also used for console output.
  • Constructor Details

    • AbstractCompilerMojo

      protected AbstractCompilerMojo(boolean isTestCompile)
      Creates a new MOJO.
      Parameters:
      isTestCompile - true for compiling tests, or false for compiling the main code
  • Method Details

    • getCompileSourceRoots

      @Nonnull protected abstract List<Path> getCompileSourceRoots()
      Returns the root directories of Java source files to compile.. If the sources are organized according the Module Source Hierarchy, then the list shall enumerate the root source directory for each module.
      Returns:
      the root directories of Java source files to compile
    • getIncludes

      protected abstract Set<String> getIncludes()
      Returns the inclusion filters for the compiler, or an empty list for all Java source files.. The filter patterns are described in FileSystem.getPathMatcher(String). If no syntax is specified, the default syntax is "glob".
      Returns:
      the inclusion filters for the compiler, or an empty list for all Java source files
    • getExcludes

      protected abstract Set<String> getExcludes()
      Returns the exclusion filters for the compiler, or an empty list if none.. The filter patterns are described in FileSystem.getPathMatcher(String). If no syntax is specified, the default syntax is "glob".
      Returns:
      the exclusion filters for the compiler, or an empty list if none
    • getIncrementalExcludes

      protected abstract Set<String> getIncrementalExcludes()
      Returns the exclusion filters for the incremental calculation.. Updated source files, if excluded by this filter, will not cause the project to be rebuilt.
      Returns:
      the exclusion filters for the incremental calculation
      See Also:
      • SourceFile.ignoreModification
    • getOutputDirectory

      @Nonnull protected abstract Path getOutputDirectory()
      Returns the destination directory (or class output directory) for class files.. This directory will be given to the -d Java compiler option.
      Returns:
      the destination directory (or class output directory) for class files
    • getSource

      @Nullable protected String getSource()
      Returns the --source argument for the Java compiler.. The default implementation returns the source value.
      Returns:
      the --source argument for the Java compiler
    • getTarget

      @Nullable protected String getTarget()
      Returns the --target argument for the Java compiler.. The default implementation returns the target value.
      Returns:
      the --target argument for the Java compiler
    • getRelease

      @Nullable protected String getRelease()
      Returns the --release argument for the Java compiler.. The default implementation returns the release value.
      Returns:
      the --release argument for the Java compiler
    • getGeneratedSourcesDirectory

      @Nullable protected abstract Path getGeneratedSourcesDirectory()
      Returns the path where to place generated source files created by annotation processing..
      Returns:
      the path where to place generated source files created by annotation processing
    • addImplicitDependencies

      protected void addImplicitDependencies(Map<org.apache.maven.api.PathType,List<Path>> addTo, boolean hasModuleDeclaration) throws IOException
      Adds dependencies others than the ones declared in POM file. The typical case is the compilation of tests, which depends on the main compilation outputs. The default implementation does nothing.
      Parameters:
      addTo - where to add dependencies
      hasModuleDeclaration - whether the main sources have or should have a module-info file
      Throws:
      IOException - if this method needs to walk through directories and that operation failed
    • addModuleOptions

      protected void addModuleOptions(org.apache.maven.api.services.DependencyResolverResult dependencies, Options addTo) throws IOException
      Generates options for handling the given dependencies. This method should do nothing when compiling the main classes, because the module-info.java file should contain all the required configuration. However, this method may need to add some -add-reads options when compiling the test classes.
      Parameters:
      dependencies - the project dependencies
      addTo - where to add the options
      Throws:
      IOException - if the module information of a dependency cannot be read
    • getDebugFileName

      @Nullable protected abstract String getDebugFileName()
      Returns the file where to dump the command-line when debug logging is enabled or when the compilation failed.. For example, if the value is "javac", then the Java compiler can be launched from the command-line by typing javac @target/javac.args. The debug file will contain the compiler options together with the list of source files to compile.

      Note: debug logging should not be confused with the debug flag.

      Returns:
      the file where to dump the command-line when debug logging is enabled or when the compilation failed
    • execute

      public void execute() throws org.apache.maven.api.plugin.MojoException
      Runs the Java compiler.
      Specified by:
      execute in interface org.apache.maven.api.plugin.Mojo
      Throws:
      org.apache.maven.api.plugin.MojoException - if the compiler cannot be run
    • acceptParameters

      protected Options acceptParameters(OptionChecker compiler)
      Parses the parameters declared in the MOJO.
      Parameters:
      compiler - the tools to use for verifying the validity of options
      Returns:
      the options after validation