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.
    • compileSourceRoots

      @Parameter protected List<String> compileSourceRoots
      The source directories containing the sources to be compiled. If null or empty, the directory will be obtained from the project manager.
    • 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.
    • 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 release version together with the source directory.
      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.
      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.MojoException
      Runs the Java compiler on the main source code.
      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.
    • acceptParameters

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

      @Nonnull protected List<Path> 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:
      getCompileSourceRoots in class AbstractCompilerMojo
      Returns:
      the root directories of Java source files to compile
    • 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
    • addImplicitDependencies

      @Deprecated(since="4.0.0") protected void addImplicitDependencies(Map<org.apache.maven.api.PathType,List<Path>> addTo, boolean hasModuleDeclaration) throws IOException
      Deprecated.
      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:
      addImplicitDependencies in class AbstractCompilerMojo
      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