Package org.apache.maven.plugin.compiler
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 Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe file where to dump the command-line when debug is activated or when the compilation failed.protected PathSpecify where to place generated source files created by annotation processing.protected PathThe output directory of the main classes.protected PathThe directory where compiled test classes go.protected booleanWhether to bypass compilation of test sources.The arguments to be passed to the test compiler.protected StringDeprecated.Deprecated.Replaced bytestCompilerArgsfor consistency with the main phase.A set of exclusion filters for the compiler.A set of inclusion filters for the compiler.A set of exclusion filters for the incremental calculation.protected Stringthe--releaseargument for the test Java compilerprotected StringThe--sourceargument for the test Java compiler.protected StringThe--targetargument for the test Java compiler.protected booleanDeprecated.Use"claspath-jar"dependency type instead, and avoidmodule-info.javain tests.Fields inherited from class org.apache.maven.plugin.compiler.AbstractCompilerMojo
annotationProcessorPaths, annotationProcessorPathsUseDepMgmt, annotationProcessors, artifactManager, basedir, compilerArgs, compilerArgument, compilerId, compilerReuseStrategy, compilerVersion, compileSourceRoots, createMissingPackageInfoClass, debug, debuglevel, enablePreview, encoding, executable, failOnError, failOnWarning, fileExtensions, forceJavacCompilerUse, forceLegacyJavacApi, fork, implicit, incrementalCompilation, jdkToolchain, logger, maxmem, meminitial, messageBuilderFactory, moduleVersion, mojoStatusPath, optimize, outputFileName, outputTimestamp, parameters, proc, project, projectManager, release, session, showCompilationChanges, showDeprecation, showWarnings, skipMultiThreadWarning, source, staleMillis, target, toolchainManager, useIncrementalCompilation, verbose -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateExecutor(DiagnosticListener<? super JavaFileObject> listener) Creates a new task for compiling the test classes.voidexecute()Runs the Java compiler on the test source code.protected StringReturns the file where to dump the command-line when debug is activated or when the compilation failed.Returns the exclusion filters for the compiler, or an empty set if none.protected PathReturns the path where to place generated source files created by annotation processing on the test classes.Returns the inclusion filters for the compiler, or an empty set for all Java source files.Returns the exclusion filters for the incremental calculation, or an empty set if none.protected PathReturns the destination directory for test class files.protected StringIf a different release version has been specified for the tests, returns that version.protected StringIf a different source version has been specified for the tests, returns that version.protected StringIf a different target version has been specified for the tests, returns that version.parseParameters(OptionChecker compiler) Parses the parameters declared in the MOJO.Methods inherited from class org.apache.maven.plugin.compiler.AbstractCompilerMojo
compiler
-
Field Details
-
skip
@Parameter(property="maven.test.skip") protected boolean skipWhether 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 generatedTestSourcesDirectorySpecify where to place generated source files created by annotation processing.- Since:
- 2.2
- See Also:
-
testIncludes
A set of inclusion filters for the compiler.- See Also:
-
testExcludes
A set of exclusion filters for the compiler.- See Also:
-
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
The--sourceargument for the test Java compiler.- Since:
- 2.1
- See Also:
-
testTarget
The--targetargument for the test Java compiler.- Since:
- 2.1
- See Also:
-
testRelease
the--releaseargument for the test Java compiler- Since:
- 3.6
- See Also:
-
testCompilerArgs
The arguments to be passed to the test compiler. If this parameter is specified, it replacesAbstractCompilerMojo.compilerArgs. Otherwise, thecompilerArgsparameter is used.- Since:
- 4.0.0
- See Also:
-
testCompilerArguments
Deprecated.Replaced bytestCompilerArgsfor consistency with the main phase.The arguments to be passed to test compiler.- Since:
- 2.1
-
testCompilerArgument
Deprecated.UsetestCompilerArgsinstead.The single argument string to be passed to the test compiler. If this parameter is specified, it replacesAbstractCompilerMojo.compilerArgument. Otherwise, thecompilerArgumentparameter is used.- Since:
- 2.1
- See Also:
-
outputDirectory
@Parameter(defaultValue="${project.build.testOutputDirectory}", required=true) protected Path outputDirectoryThe directory where compiled test classes go. This parameter should only be modified in special cases. See theCompilerMojo.outputDirectoryfor more information.- See Also:
-
mainOutputDirectory
@Parameter(defaultValue="${project.build.outputDirectory}", required=true, readonly=true) protected Path mainOutputDirectoryThe output directory of the main classes. This directory will be added to the class-path or module-path. Its value should be the same asCompilerMojo.outputDirectory.- See Also:
-
useModulePath
Deprecated.Use"claspath-jar"dependency type instead, and avoidmodule-info.javain tests.Whether to place the main classes on the module path whenmodule-infois present. Whenfalse, always places the main classes on the class path. Dependencies are also placed on the class-path, unless their type ismodule-jar.- Since:
- 3.11
-
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 typingjavac @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.verboseflag totrueor by specifying the--verboseoption 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.MojoExceptionRuns the Java compiler on the test source code. Ifskipistrue, 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:
executein interfaceorg.apache.maven.api.plugin.Mojo- Overrides:
executein classAbstractCompilerMojo- Throws:
org.apache.maven.api.plugin.MojoException- if the compiler cannot be run.
-
parseParameters
Parses the parameters declared in the MOJO.- Overrides:
parseParametersin classAbstractCompilerMojo- Parameters:
compiler- the tools to use for verifying the validity of options- Returns:
- the options after validation
-
getGeneratedSourcesDirectory
Returns the path where to place generated source files created by annotation processing on the test classes.- Specified by:
getGeneratedSourcesDirectoryin classAbstractCompilerMojo- Returns:
- the path where to place generated source files created by annotation processing on the test classes
-
getIncludes
Returns the inclusion filters for the compiler, or an empty set for all Java source files.- Specified by:
getIncludesin classAbstractCompilerMojo- Returns:
- the inclusion filters for the compiler, or an empty set for all Java source files
-
getExcludes
Returns the exclusion filters for the compiler, or an empty set if none.- Specified by:
getExcludesin classAbstractCompilerMojo- Returns:
- the exclusion filters for the compiler, or an empty set if none
-
getIncrementalExcludes
Returns the exclusion filters for the incremental calculation, or an empty set if none.- Specified by:
getIncrementalExcludesin classAbstractCompilerMojo- Returns:
- the exclusion filters for the incremental calculation, or an empty set if none
- See Also:
-
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:
getSourcein classAbstractCompilerMojo- Returns:
- the
--sourceargument for the Java compiler
-
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:
getTargetin classAbstractCompilerMojo- Returns:
- the
--targetargument for the Java compiler
-
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:
getReleasein classAbstractCompilerMojo- Returns:
- the
--releaseargument for the Java compiler
-
getOutputDirectory
Returns the destination directory for test class files.- Specified by:
getOutputDirectoryin classAbstractCompilerMojo- Returns:
- the destination directory for test class files
-
getDebugFileName
Returns the file where to dump the command-line when debug is activated or when the compilation failed.- Specified by:
getDebugFileNamein classAbstractCompilerMojo- 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:
createExecutorin classAbstractCompilerMojo- Parameters:
listener- where to send compilation warnings, ornullfor 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 MOJOIOException- if an error occurred while creating the output directory or scanning the source directories
-
testCompilerArgsinstead.