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 Details

    • skipMain

      @Parameter(property="maven.main.skip") protected boolean skipMain
      Set this to true 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 generatedSourcesDirectory
      Specify where to place generated source files created by annotation processing.
      Since:
      2.2
    • includes

      @Parameter protected Set<String> includes
      A set of inclusion filters for the compiler.
    • excludes

      @Parameter protected Set<String> excludes
      A set of exclusion filters for the compiler.
    • incrementalExcludes

      @Parameter protected Set<String> 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 outputDirectory
      The directory for compiled classes.
      See Also:
    • projectArtifact

      @Parameter(defaultValue="${project.mainArtifact}", readonly=true, required=true) protected org.apache.maven.api.ProducedArtifact projectArtifact
      Projects main artifact.
    • multiReleaseOutput

      @Parameter @Deprecated(since="4.0.0") protected boolean multiReleaseOutput
      Deprecated.
      Replaced by specifying the <targetVersion> value inside a <source> element.
      When set to true, the classes will be placed in META-INF/versions/${release}.

      Note: A jar is only a multi-release jar if META-INF/MANIFEST.MF contains Multi-Release: true. You need to set this by configuring the maven-jar-plugin. This implies that you cannot test a multi-release jar using the outputDirectory.

      Since:
      3.7.1
    • debugFileName

      @Parameter(defaultValue="javac.args") protected String 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 typing javac @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 to true 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.MojoException
      Runs the Java compiler on the main source code. If skipMain is true, 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 interface org.apache.maven.api.plugin.Mojo
      Overrides:
      execute in class AbstractCompilerMojo
      Throws:
      org.apache.maven.api.plugin.MojoException - if the compiler cannot be run.
    • parseParameters

      public Options parseParameters(OptionChecker compiler)
      Parses the parameters declared in the MOJO.
      Overrides:
      parseParameters in class AbstractCompilerMojo
      Parameters:
      compiler - the tools to use for verifying the validity of options
      Returns:
      the options after validation
    • getGeneratedSourcesDirectory

      @Nullable protected Path getGeneratedSourcesDirectory()
      Returns the path where to place generated source files created by annotation processing on the main classes.
      Specified by:
      getGeneratedSourcesDirectory in class AbstractCompilerMojo
      Returns:
      the path where to place generated source files created by annotation processing on the main classes
    • getIncludes

      protected Set<String> getIncludes()
      Returns the inclusion filters for the compiler, or an empty set for all Java source files.
      Specified by:
      getIncludes in class AbstractCompilerMojo
      Returns:
      the inclusion filters for the compiler, or an empty set for all Java source files
    • getExcludes

      protected Set<String> getExcludes()
      Returns the exclusion filters for the compiler, or an empty set if none.
      Specified by:
      getExcludes in class AbstractCompilerMojo
      Returns:
      the exclusion filters for the compiler, or an empty set if none
    • getIncrementalExcludes

      protected Set<String> getIncrementalExcludes()
      Returns the exclusion filters for the incremental calculation, or an empty set if none.
      Specified by:
      getIncrementalExcludes in class AbstractCompilerMojo
      Returns:
      the exclusion filters for the incremental calculation, or an empty set if none
      See Also:
      • SourceFile.ignoreModification
    • getOutputDirectory

      @Nonnull protected Path getOutputDirectory()
      Returns the destination directory for main class files. If multiReleaseOutput is true (deprecated), the output will be in a META-INF/versions subdirectory.
      Specified by:
      getOutputDirectory in class AbstractCompilerMojo
      Returns:
      the destination directory for main class files
    • getDebugFileName

      @Nullable protected String getDebugFileName()
      Returns the file where to dump the command-line when debug is activated or when the compilation failed.
      Specified by:
      getDebugFileName in class AbstractCompilerMojo
      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 class AbstractCompilerMojo
      Parameters:
      listener - where to send compilation warnings, or null 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 MOJO
      IOException - if an error occurred while creating the output directory or scanning the source directories