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

      @Parameter protected List<String> compileSourceRoots
      The source directories containing the test-source to be compiled.
      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.
      Since:
      3.10.0
      See Also:
  • Constructor Details

    • TestCompilerMojo

      public TestCompilerMojo()
      Creates a new test compiler MOJO.
  • Method Details

    • execute

      public void execute() throws org.apache.maven.api.plugin.MojoException
      Runs the Java compiler on the test 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 for the tests..
      Specified by:
      getCompileSourceRoots in class AbstractCompilerMojo
      Returns:
      the root directories of Java source files to compile for the tests
    • 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
    • addImplicitDependencies

      protected void addImplicitDependencies(Map<org.apache.maven.api.PathType,List<Path>> addTo, boolean hasModuleDeclaration)
      Adds the main compilation output directories as test dependencies.
      Overrides:
      addImplicitDependencies in class AbstractCompilerMojo
      Parameters:
      addTo - where to add dependencies
      hasModuleDeclaration - whether the main sources have or should have a module-info file
    • addModuleOptions

      protected void addModuleOptions(org.apache.maven.api.services.DependencyResolverResult dependencies, Options addTo) throws IOException
      Generates the --add-modules and --add-reads options for the dependencies that are not in the main compilation. This method is invoked only if hasModuleDeclaration is true.
      Overrides:
      addModuleOptions in class AbstractCompilerMojo
      Parameters:
      dependencies - the project dependencies
      addTo - where to add the options
      Throws:
      IOException - if the module information of a dependency cannot be read