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 TypeFieldDescriptionThe source directories containing the test-source to be compiled.protected String
The file where to dump the command-line when debug is activated or when the compilation failed.protected Path
Specify where to place generated source files created by annotation processing.protected Path
The output directory of the main classes.protected Path
The directory where compiled test classes go.protected boolean
Whether to bypass compilation of test sources.The arguments to be passed to the test compiler.protected String
Deprecated.Deprecated.Replaced bytestCompilerArgs
for 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 String
the--release
argument for the test Java compilerprotected String
The--source
argument for the test Java compiler.protected String
The--target
argument for the test Java compiler.protected boolean
Deprecated.Use"claspath-jar"
dependency type instead, and avoidmodule-info.java
in tests.Fields inherited from class org.apache.maven.plugin.compiler.AbstractCompilerMojo
annotationProcessorPaths, annotationProcessorPathsUseDepMgmt, annotationProcessors, artifactManager, basedir, compilerArgs, compilerArgument, compilerId, compilerReuseStrategy, compilerVersion, 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 TypeMethodDescriptionprotected Options
acceptParameters
(OptionChecker compiler) Parses the parameters declared in the MOJO.protected void
addImplicitDependencies
(Map<org.apache.maven.api.PathType, List<Path>> addTo, boolean hasModuleDeclaration) Adds the main compilation output directories as test dependencies.protected void
addModuleOptions
(org.apache.maven.api.services.DependencyResolverResult dependencies, Options addTo) Generates the--add-modules
and--add-reads
options for the dependencies that are not in the main compilation.void
execute()
Runs the Java compiler on the test source code.Returns the root directories of Java source files to compile for the tests.protected String
Returns 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 Path
Returns 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 Path
Returns the destination directory for test class files.protected String
If a different release version has been specified for the tests, returns that version.protected String
If a different source version has been specified for the tests, returns that version.protected String
If a different target version has been specified for the tests, returns that version.
-
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:
-
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 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--source
argument for the test Java compiler.- Since:
- 2.1
- See Also:
-
testTarget
The--target
argument for the test Java compiler.- Since:
- 2.1
- See Also:
-
testRelease
the--release
argument 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, thecompilerArgs
parameter is used.- Since:
- 4.0.0
- See Also:
-
testCompilerArguments
Deprecated.Replaced bytestCompilerArgs
for consistency with the main phase.The arguments to be passed to test compiler.- Since:
- 2.1
-
testCompilerArgument
Deprecated.UsetestCompilerArgs
instead.The single argument string to be passed to the test compiler. If this parameter is specified, it replacesAbstractCompilerMojo.compilerArgument
. Otherwise, thecompilerArgument
parameter 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.outputDirectory
for 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.java
in tests.Whether to place the main classes on the module path whenmodule-info
is 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.- 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.MojoExceptionRuns the Java compiler on the test source code.- Specified by:
execute
in interfaceorg.apache.maven.api.plugin.Mojo
- Overrides:
execute
in classAbstractCompilerMojo
- Throws:
org.apache.maven.api.plugin.MojoException
- if the compiler cannot be run.
-
acceptParameters
Parses the parameters declared in the MOJO.- Overrides:
acceptParameters
in classAbstractCompilerMojo
- Parameters:
compiler
- the tools to use for verifying the validity of options- Returns:
- the options after validation
-
getCompileSourceRoots
Returns the root directories of Java source files to compile for the tests..- Specified by:
getCompileSourceRoots
in classAbstractCompilerMojo
- Returns:
- the root directories of Java source files to compile for the tests
-
getGeneratedSourcesDirectory
Returns the path where to place generated source files created by annotation processing on the test classes..- Specified by:
getGeneratedSourcesDirectory
in 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:
getIncludes
in 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:
getExcludes
in 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:
getIncrementalExcludes
in 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:
getSource
in classAbstractCompilerMojo
- Returns:
- the
--source
argument 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:
getTarget
in classAbstractCompilerMojo
- Returns:
- the
--target
argument 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:
getRelease
in classAbstractCompilerMojo
- Returns:
- the
--release
argument for the Java compiler
-
getOutputDirectory
Returns the destination directory for test class files..- Specified by:
getOutputDirectory
in 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:
getDebugFileName
in classAbstractCompilerMojo
- 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 classAbstractCompilerMojo
- Parameters:
addTo
- where to add dependencieshasModuleDeclaration
- whether the main sources have or should have amodule-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 ifhasModuleDeclaration
istrue
.- Overrides:
addModuleOptions
in classAbstractCompilerMojo
- Parameters:
dependencies
- the project dependenciesaddTo
- where to add the options- Throws:
IOException
- if the module information of a dependency cannot be read
-
testCompilerArgs
instead.