Class TestCompilerMojo

java.lang.Object
org.apache.maven.plugin.compiler.AbstractCompilerMojo
org.apache.maven.plugin.compiler.TestCompilerMojo
All Implemented Interfaces:
org.apache.maven.api.plugin.Mojo

@Mojo(name="testCompile", defaultPhase="test-compile") public class TestCompilerMojo extends AbstractCompilerMojo
Compiles application test sources. Each instance shall be used only once, then discarded.
Since:
2.0
Author:
Jason van Zyl, Martin Desruisseaux
See Also:
  • Field Details

    • skip

      @Parameter(property="maven.test.skip") protected boolean skip
      Whether to bypass compilation of test sources. Its use is not recommended, but quite convenient on occasion.
      See Also:
    • generatedTestSourcesDirectory

      @Parameter(defaultValue="${project.build.directory}/generated-test-sources/test-annotations") protected Path generatedTestSourcesDirectory
      Specify where to place generated source files created by annotation processing.
      Since:
      2.2
      See Also:
    • testIncludes

      @Parameter protected Set<String> testIncludes
      A set of inclusion filters for the compiler.
      See Also:
    • testExcludes

      @Parameter protected Set<String> testExcludes
      A set of exclusion filters for the compiler.
      See Also:
    • testIncrementalExcludes

      @Parameter protected Set<String> testIncrementalExcludes
      A set of exclusion filters for the incremental calculation. Updated files, if excluded by this filter, will not cause the project to be rebuilt.
      Since:
      3.11
      See Also:
    • testSource

      @Parameter(property="maven.compiler.testSource") protected String testSource
      The --source argument for the test Java compiler.
      Since:
      2.1
      See Also:
    • testTarget

      @Parameter(property="maven.compiler.testTarget") protected String testTarget
      The --target argument for the test Java compiler.
      Since:
      2.1
      See Also:
    • testRelease

      @Parameter(property="maven.compiler.testRelease") protected String testRelease
      the --release argument for the test Java compiler
      Since:
      3.6
      See Also:
    • testCompilerArgs

      @Parameter protected List<String> testCompilerArgs
      The arguments to be passed to the test compiler. If this parameter is specified, it replaces AbstractCompilerMojo.compilerArgs. Otherwise, the compilerArgs parameter is used.
      Since:
      4.0.0
      See Also:
    • testCompilerArguments

      @Parameter @Deprecated(since="4.0.0") protected Map<String,String> testCompilerArguments
      Deprecated.
      Replaced by testCompilerArgs for consistency with the main phase.
      The arguments to be passed to test compiler.
      Since:
      2.1
    • testCompilerArgument

      @Parameter @Deprecated(since="4.0.0") protected String testCompilerArgument
      Deprecated.
      Use testCompilerArgs instead.
      The single argument string to be passed to the test compiler. If this parameter is specified, it replaces AbstractCompilerMojo.compilerArgument. Otherwise, the compilerArgument parameter is used.
      Since:
      2.1
      See Also:
    • outputDirectory

      @Parameter(defaultValue="${project.build.testOutputDirectory}", required=true) protected Path outputDirectory
      The directory where compiled test classes go. This parameter should only be modified in special cases. See the CompilerMojo.outputDirectory for more information.
      See Also:
    • mainOutputDirectory

      @Parameter(defaultValue="${project.build.outputDirectory}", required=true, readonly=true) protected Path mainOutputDirectory
      The output directory of the main classes. This directory will be added to the class-path or module-path. Its value should be the same as CompilerMojo.outputDirectory.
      See Also:
    • useModulePath

      @Deprecated(since="4.0.0") @Parameter(defaultValue="true") protected boolean useModulePath
      Deprecated.
      Use "claspath-jar" dependency type instead, and avoid module-info.java in tests.
      Whether to place the main classes on the module path when module-info is present. When false, always places the main classes on the class path. Dependencies are also placed on the class-path, unless their type is module-jar.
      Since:
      3.11
    • debugFileName

      @Parameter(defaultValue="javac-test.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-test", then the Java compiler can be launched from the command-line by typing javac @target/javac-test.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 test 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
      See Also:
  • Constructor Details

    • TestCompilerMojo

      public TestCompilerMojo()
      Creates a new compiler MOJO for the tests.
  • Method Details

    • execute

      public void execute() throws org.apache.maven.api.plugin.MojoException
      Runs the Java compiler on the test source code. If skip 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 test classes.
      Specified by:
      getGeneratedSourcesDirectory in class AbstractCompilerMojo
      Returns:
      the path where to place generated source files created by annotation processing on the test 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
    • getSource

      @Nullable protected String getSource()
      If a different source version has been specified for the tests, returns that version. Otherwise returns the same source version as the main code.
      Overrides:
      getSource in class AbstractCompilerMojo
      Returns:
      the --source argument for the Java compiler
    • getTarget

      @Nullable protected String getTarget()
      If a different target version has been specified for the tests, returns that version. Otherwise returns the same target version as the main code.
      Overrides:
      getTarget in class AbstractCompilerMojo
      Returns:
      the --target argument for the Java compiler
    • getRelease

      @Nullable protected String getRelease()
      If a different release version has been specified for the tests, returns that version. Otherwise returns the same release version as the main code.
      Overrides:
      getRelease in class AbstractCompilerMojo
      Returns:
      the --release argument for the Java compiler
    • getOutputDirectory

      @Nonnull protected Path getOutputDirectory()
      Returns the destination directory for test class files.
      Specified by:
      getOutputDirectory in class AbstractCompilerMojo
      Returns:
      the destination directory for test 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 test 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 tests 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