Fork me on GitHub

aspectj:test-compile

Full name:

dev.aspectj:aspectj-maven-plugin:1.14:test-compile

Description:

Weaves all test classes. AspectJ Compiler Plugin.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: test.
  • The goal is thread-safe and supports parallel builds.
  • Binds by default to the lifecycle phase: test-compile.

Optional Parameters

Name Type Since Description
<additionalCompilerArgs> List<String> 1.13 Sets additional compiler arguments, e.g.
<additionalCompilerArgs>
  <arg>-Xmaxerrs=1000</arg>
  <arg>-Xlint</arg>
  <arg>-J-Duser.language=en_us</arg>
</additionalCompilerArgs>
This option can be used in case you want to use AJC options not (yet) supported by this plugin.

Caveat: Be careful when using this option and select the additional compiler arguments wisely, because behaviour is undefined if you add arguments which have already been added by the plugin using regular parameters or their default values. The resulting compiler command line will in that case contain duplicate arguments, which might be illegal depending on the specific argument. Do not expect to be able to manually override existing arguments using this option or to replace whole argument lists.


<ajdtBuildDefFile> String - Where to find the ajdt build definition file. If set this will override the use of project sourcedirs.
<argumentFileDirectory> File - The directory for the argument file, see argumentFileName.

For reproducible builds, please change the directory to be outside the outputDirectory, because argument files contain path names, which can vary between build systems. So you do not want an argument file to end up in your build artifact (e.g. JAR file) for a reproducible build.

Caveat: If you configure a common directory, e.g. ${project.build.directory}/aj-build, in the plugin configuration, please make sure to choose different argumentFileNames for compile vs test-compile goal execution configurations to avoid one file overwriting the other.


Default value is: ${project.build.testOutputDirectory}.
<argumentFileName> String - The filename holding AJC build arguments.

By default, the file will be placed in the respective build output directory, i.e. in the same directory where your application or test classes reside, and will contain all the arguments passed to the AJC compiler in the last run, and also all the files included in the AJC build. The file is also used to determine if recompilation is necessary in subsequent builds. The argumentFileDirectory can be changed, which is helpful for reproducible builds.

A typical builddef.lst file might look like this:

-1.8
-encoding
UTF-8
-classpath
/my/library/lib.jar:/somewhere/aspectjrt.jar:/my/project/target/classes
-d
/my/project/target/classes
/my/project/src/main/java/org/acme/ValidationAspect.java

Default value is: builddef.lst.
<aspectDirectory> String - The source directory for the aspects.
Default value is: src/main/aspect.
<aspectLibraries> Module[] - Weave binary aspects from the jars. The aspects should have been output by the same version of the compiler. The modules must also be dependencies of the project. Corresponds to ajc -aspectpath option
<bootclasspath> String - Override location of VM's bootclasspath for purposes of evaluating types when compiling. Path is a single argument containing a list of paths to zip files or directories, delimited by the platform-specific path delimiter.
<complianceLevel> String - Specify compiler compliance setting (same as setting source and target to the same level). This sets a compiler option like -1.7 or -11.

Using this option overrides source, target. If you want the latter two to be different, make sure not to use this option.


See also: AjcHelper.isValidComplianceLevel(java.lang.String)
<crossrefs> boolean - generate .ajsym file into the output directory
<deprecation> boolean - Toggle warning messages on deprecations
<emacssym> boolean - Generate .ajesym symbol files for emacs support.
<enablePreview> boolean 1.13 Activates compiler preview features (e.g. sealed classes in Java 16) when used with a suitable JDK version.

Please note: You cannot run code compiled with preview features on any other JDK than the one used for compilation. For example, records compiled with preview on JDK 15 cannot be used on JDK 16 without recompilation. This is a JVM limitation unrelated to AspectJ. Also, e.g. sealed classes are preview-1 on JDK 15 and preview-2 on JDK 16. You still need to recompile, no matter what.


Default value is: false.
<encoding> String - Specify default source encoding format.
User property is: project.build.sourceEncoding.
<excludes> String[] - List of ant-style patterns used to specify the aspects that should be excluded when compiling. When none specified all .java and .aj files in the project source directories, or directories specified by the ajdtDefFile property are included.
<forceAjcCompile> boolean - Forces re-compilation, regardless of whether the compiler arguments or the sources have changed.
Default value is: false.
<generatedTestSourcesDirectory> File - The directory for sources generated by annotation processing.
Default value is: ${project.build.directory}/generated-test-sources/aspectj-maven-plugin.
<includes> String[] - List of ant-style patterns used to specify the aspects that should be included when compiling. When none specified all .java and .aj files in the project source directories, or directories specified by the ajdtDefFile property are included.
<javaModules> Module[] 1.13 Java 9+ modules to build the module path from. Corresponds to ajc --module-path option.
<noImportError> boolean - Emit no errors for unresolved imports;
<outxml> boolean - Generate aop.xml file for load-time weaving with default name (/META-INF/aop.xml).
<outxmlfile> String - Generate aop.xml file for load-time weaving with custom name.
<parameters> boolean - Set the compiler "parameters" argument.
<preserveAllLocals> boolean - Preserve all local variables during code generation (to facilitate debugging).
<proc> String - Set the compiler "proc" argument. Aspectj supports Annotation processing since 1.8.2, it can been disabled by proc:none.
See also: AspectJ 1.8.2 Release notes, Annotation Processing
<proceedOnError> boolean - Keep compiling after error, dumping class files with problem methods
<referenceInfo> boolean - Compute reference information.
<release> String 1.13 Specify the Java target API version to use for cross-compilation to an older JDK's API by using the --release N compiler option (available on JDK 9+). This is similar to using complianceLevel (or identical source and target) in combination with setting the boot classpath to an older JDK. Use this option in order to make sure that not only the generated byte code conforms to the target level but also the code is compiled against a specific JDK's API.

Using this option overrides all of complianceLevel, source, target. Please note that before AspectJ 1.9.8.M1, the --release N compiler option was not working correctly.

See AjcHelper.isValidComplianceLevel(java.lang.String) for details about valid version numbers in general, but please note that permitted version numbers for this option depend on the JDK used for compilation, as more recent JDKs might drop cross-compilation support for older ones.


<repeat> int - Repeat compilation process N times (typically to do performance analysis).
<showWeaveInfo> boolean - Emit messages about weaving
<skip> boolean - Skip plugin execution.
Default value is: false.
User property is: aspectj.skip.
<source> String - Specify source code language level (1.3 to 1.9 or a number ≥ 5) by using the -source N compiler option.

If unspecified, the AspectJ compiler's default (1.4 for AspectJ 1.9.7) is used. Please note, that target defaults to the value set here.


See also: AjcHelper.isValidComplianceLevel(java.lang.String)
<target> String - Specify target byte code level (1.3 to 1.9 or a number ≥ 5) by using the -source N compiler option.

If unspecified, this value defaults to source. If neither source nor target are specified, the AspectJ compiler's default is used.


See also: AjcHelper.isValidComplianceLevel(java.lang.String)
<testAspectDirectory> String - The source directory for the test aspects.
Default value is: src/test/aspect.
<testSources> Scanner[] 1.4

Set the java test source folders to use, specifying the includes and excludes.

If you don't specify this parameter, all java test sources of the current project will be used. If you specify this parameter as an empty tag (i.e. <testSources/>), all test source folders will be ignored. Otherwise specify the test source folder(s) to use.


See also: org.codehaus.plexus.util.DirectoryScanner
<verbose> boolean - Emit messages about accessed/processed compilation units
<warn> String - Emit warnings for any instances of the comma-delimited list of questionable code. Supported values are shown in the list below, with their respective explanations - as copied directly from the AJC reference.
constructorName
method with constructor name
packageDefaultMethod
attempt to override package-default method
deprecation
usage of deprecated type or member
maskedCatchBlocks
hidden catch block
unusedLocals
local variable never read
unusedArguments
method argument never read
unusedImports
import statement not used by code in file
none
suppress all compiler warnings

See also: Eclipse AJC reference
<weaveDependencies> Module[] - List of of modules to weave (into target directory). Corresponds to ajc -inpath option (or -injars for pre-1.2 (which is not supported)).
<weaveDirectories> String[] 1.4 List of of directories with .class files to weave (into target directory). Corresponds to ajc -inpath option.
<weaveMainSourceFolder> boolean - Flag to indicate if the main source dirs should be a part of the compile process. Note! This will make all classes in main source dir appear in the test output dir also, potentially overwriting test resources.
Default value is: false.
<weaveWithAspectsInMainSourceFolder> boolean - Flag to indicate if aspects in the the main source dirs should be a part of the compile process
Default value is: true.
<XaddSerialVersionUID> boolean - Causes the compiler to calculate and add the SerialVersionUID field to any type implementing java.io.Serializable that is affected by an aspect. The field is calculated based on the class before weaving has taken place.
<Xajruntimetarget> String - (Experimental) Allows code to be generated that targets a 1.2 or a 1.5 level AspectJ runtime (default 1.5)
Default value is: 1.5.
<XhasMember> boolean 1.3 Enables the compiler to support hasmethod(method_pattern) and hasfield(field_pattern) type patterns, but only within declare statements. It's experimental and undocumented because it may change, and because it doesn't yet take into account ITDs.
<Xjoinpoints> String - supply a comma separated list of new joinpoints that can be identified by pointcuts. Values are: arrayconstruction, synchronization
<Xlint> String - Set default level for messages about potential programming mistakes in crosscutting code. {level} may be ignore, warning, or error. This overrides entries in org/aspectj/weaver/XlintDefault.properties from aspectjtools.jar.
<Xlintfile> File - Specify properties file to set levels for specific crosscutting messages. PropertyFile is a path to a Java .properties file that takes the same property names and values as org/aspectj/weaver/XlintDefault.properties from aspectjtools.jar, which it also overrides.
<xmlConfigured> File - Parameter which indicates an XML file containing AspectJ weaving instructions. Assigning this plugin parameter adds the -xmlConfigured option to ajc.
See also: ajc reference
<XnoInline> boolean - (Experimental) do not inline around advice
<XnotReweavable> boolean - (Experimental) Create class files that can't be subsequently rewoven by AspectJ.
<Xreweavable> boolean - (Experimental) runs weaver in reweavable mode which causes it to create woven classes that can be rewoven, subject to the restriction that on attempting a reweave all the types that advised the woven type must be accessible.
<XserializableAspects> boolean - (Experimental) Normally it is an error to declare aspects java.io.Serializable. This option removes that restriction.
<Xset> Map<String,String> 1.5 Allows the caller to provide additional arguments in a Map format. For example:
<configuration>
  <Xset>
    <overWeaving>true</overWeaving>
    <avoidFinal>false</avoidFinal>
  </Xset>
</configuration>

<XterminateAfterCompilation> boolean - Causes compiler to terminate before weaving

Parameter Details

<additionalCompilerArgs>

Sets additional compiler arguments, e.g.
<additionalCompilerArgs>
  <arg>-Xmaxerrs=1000</arg>
  <arg>-Xlint</arg>
  <arg>-J-Duser.language=en_us</arg>
</additionalCompilerArgs>
This option can be used in case you want to use AJC options not (yet) supported by this plugin.

Caveat: Be careful when using this option and select the additional compiler arguments wisely, because behaviour is undefined if you add arguments which have already been added by the plugin using regular parameters or their default values. The resulting compiler command line will in that case contain duplicate arguments, which might be illegal depending on the specific argument. Do not expect to be able to manually override existing arguments using this option or to replace whole argument lists.

  • Type: java.util.List<java.lang.String>
  • Since: 1.13
  • Required: No

<ajdtBuildDefFile>

Where to find the ajdt build definition file. If set this will override the use of project sourcedirs.
  • Type: java.lang.String
  • Required: No

<argumentFileDirectory>

The directory for the argument file, see argumentFileName.

For reproducible builds, please change the directory to be outside the outputDirectory, because argument files contain path names, which can vary between build systems. So you do not want an argument file to end up in your build artifact (e.g. JAR file) for a reproducible build.

Caveat: If you configure a common directory, e.g. ${project.build.directory}/aj-build, in the plugin configuration, please make sure to choose different argumentFileNames for compile vs test-compile goal execution configurations to avoid one file overwriting the other.

  • Type: java.io.File
  • Required: No
  • Default: ${project.build.testOutputDirectory}

<argumentFileName>

The filename holding AJC build arguments.

By default, the file will be placed in the respective build output directory, i.e. in the same directory where your application or test classes reside, and will contain all the arguments passed to the AJC compiler in the last run, and also all the files included in the AJC build. The file is also used to determine if recompilation is necessary in subsequent builds. The argumentFileDirectory can be changed, which is helpful for reproducible builds.

A typical builddef.lst file might look like this:

-1.8
-encoding
UTF-8
-classpath
/my/library/lib.jar:/somewhere/aspectjrt.jar:/my/project/target/classes
-d
/my/project/target/classes
/my/project/src/main/java/org/acme/ValidationAspect.java
  • Type: java.lang.String
  • Required: No
  • Default: builddef.lst

<aspectDirectory>

The source directory for the aspects.
  • Type: java.lang.String
  • Required: No
  • Default: src/main/aspect

<aspectLibraries>

Weave binary aspects from the jars. The aspects should have been output by the same version of the compiler. The modules must also be dependencies of the project. Corresponds to ajc -aspectpath option
  • Type: org.codehaus.mojo.aspectj.Module[]
  • Required: No

<bootclasspath>

Override location of VM's bootclasspath for purposes of evaluating types when compiling. Path is a single argument containing a list of paths to zip files or directories, delimited by the platform-specific path delimiter.
  • Type: java.lang.String
  • Required: No

<complianceLevel>

Specify compiler compliance setting (same as setting source and target to the same level). This sets a compiler option like -1.7 or -11.

Using this option overrides source, target. If you want the latter two to be different, make sure not to use this option.


See also: AjcHelper.isValidComplianceLevel(java.lang.String)
  • Type: java.lang.String
  • Required: No

<crossrefs>

generate .ajsym file into the output directory
  • Type: boolean
  • Required: No

<deprecation>

Toggle warning messages on deprecations
  • Type: boolean
  • Required: No

<emacssym>

Generate .ajesym symbol files for emacs support.
  • Type: boolean
  • Required: No

<enablePreview>

Activates compiler preview features (e.g. sealed classes in Java 16) when used with a suitable JDK version.

Please note: You cannot run code compiled with preview features on any other JDK than the one used for compilation. For example, records compiled with preview on JDK 15 cannot be used on JDK 16 without recompilation. This is a JVM limitation unrelated to AspectJ. Also, e.g. sealed classes are preview-1 on JDK 15 and preview-2 on JDK 16. You still need to recompile, no matter what.

  • Type: boolean
  • Since: 1.13
  • Required: No
  • Default: false

<encoding>

Specify default source encoding format.
  • Type: java.lang.String
  • Required: No
  • User Property: project.build.sourceEncoding

<excludes>

List of ant-style patterns used to specify the aspects that should be excluded when compiling. When none specified all .java and .aj files in the project source directories, or directories specified by the ajdtDefFile property are included.
  • Type: java.lang.String[]
  • Required: No

<forceAjcCompile>

Forces re-compilation, regardless of whether the compiler arguments or the sources have changed.
  • Type: boolean
  • Required: No
  • Default: false

<generatedTestSourcesDirectory>

The directory for sources generated by annotation processing.
  • Type: java.io.File
  • Required: No
  • Default: ${project.build.directory}/generated-test-sources/aspectj-maven-plugin

<includes>

List of ant-style patterns used to specify the aspects that should be included when compiling. When none specified all .java and .aj files in the project source directories, or directories specified by the ajdtDefFile property are included.
  • Type: java.lang.String[]
  • Required: No

<javaModules>

Java 9+ modules to build the module path from. Corresponds to ajc --module-path option.
  • Type: org.codehaus.mojo.aspectj.Module[]
  • Since: 1.13
  • Required: No

<noImportError>

Emit no errors for unresolved imports;
  • Type: boolean
  • Required: No

<outxml>

Generate aop.xml file for load-time weaving with default name (/META-INF/aop.xml).
  • Type: boolean
  • Required: No

<outxmlfile>

Generate aop.xml file for load-time weaving with custom name.
  • Type: java.lang.String
  • Required: No

<parameters>

Set the compiler "parameters" argument.
  • Type: boolean
  • Required: No

<preserveAllLocals>

Preserve all local variables during code generation (to facilitate debugging).
  • Type: boolean
  • Required: No

<proc>

Set the compiler "proc" argument. Aspectj supports Annotation processing since 1.8.2, it can been disabled by proc:none.
See also: AspectJ 1.8.2 Release notes, Annotation Processing
  • Type: java.lang.String
  • Required: No

<proceedOnError>

Keep compiling after error, dumping class files with problem methods
  • Type: boolean
  • Required: No

<referenceInfo>

Compute reference information.
  • Type: boolean
  • Required: No

<release>

Specify the Java target API version to use for cross-compilation to an older JDK's API by using the --release N compiler option (available on JDK 9+). This is similar to using complianceLevel (or identical source and target) in combination with setting the boot classpath to an older JDK. Use this option in order to make sure that not only the generated byte code conforms to the target level but also the code is compiled against a specific JDK's API.

Using this option overrides all of complianceLevel, source, target. Please note that before AspectJ 1.9.8.M1, the --release N compiler option was not working correctly.

See AjcHelper.isValidComplianceLevel(java.lang.String) for details about valid version numbers in general, but please note that permitted version numbers for this option depend on the JDK used for compilation, as more recent JDKs might drop cross-compilation support for older ones.

  • Type: java.lang.String
  • Since: 1.13
  • Required: No

<repeat>

Repeat compilation process N times (typically to do performance analysis).
  • Type: int
  • Required: No

<showWeaveInfo>

Emit messages about weaving
  • Type: boolean
  • Required: No

<skip>

Skip plugin execution.
  • Type: boolean
  • Required: No
  • User Property: aspectj.skip
  • Default: false

<source>

Specify source code language level (1.3 to 1.9 or a number ≥ 5) by using the -source N compiler option.

If unspecified, the AspectJ compiler's default (1.4 for AspectJ 1.9.7) is used. Please note, that target defaults to the value set here.


See also: AjcHelper.isValidComplianceLevel(java.lang.String)
  • Type: java.lang.String
  • Required: No

<target>

Specify target byte code level (1.3 to 1.9 or a number ≥ 5) by using the -source N compiler option.

If unspecified, this value defaults to source. If neither source nor target are specified, the AspectJ compiler's default is used.


See also: AjcHelper.isValidComplianceLevel(java.lang.String)
  • Type: java.lang.String
  • Required: No

<testAspectDirectory>

The source directory for the test aspects.
  • Type: java.lang.String
  • Required: No
  • Default: src/test/aspect

<testSources>

Set the java test source folders to use, specifying the includes and excludes.

If you don't specify this parameter, all java test sources of the current project will be used. If you specify this parameter as an empty tag (i.e. <testSources/>), all test source folders will be ignored. Otherwise specify the test source folder(s) to use.


See also: org.codehaus.plexus.util.DirectoryScanner
  • Type: org.codehaus.plexus.util.Scanner[]
  • Since: 1.4
  • Required: No

<verbose>

Emit messages about accessed/processed compilation units
  • Type: boolean
  • Required: No

<warn>

Emit warnings for any instances of the comma-delimited list of questionable code. Supported values are shown in the list below, with their respective explanations - as copied directly from the AJC reference.
constructorName
method with constructor name
packageDefaultMethod
attempt to override package-default method
deprecation
usage of deprecated type or member
maskedCatchBlocks
hidden catch block
unusedLocals
local variable never read
unusedArguments
method argument never read
unusedImports
import statement not used by code in file
none
suppress all compiler warnings

See also: Eclipse AJC reference
  • Type: java.lang.String
  • Required: No

<weaveDependencies>

List of of modules to weave (into target directory). Corresponds to ajc -inpath option (or -injars for pre-1.2 (which is not supported)).
  • Type: org.codehaus.mojo.aspectj.Module[]
  • Required: No

<weaveDirectories>

List of of directories with .class files to weave (into target directory). Corresponds to ajc -inpath option.
  • Type: java.lang.String[]
  • Since: 1.4
  • Required: No

<weaveMainSourceFolder>

Flag to indicate if the main source dirs should be a part of the compile process. Note! This will make all classes in main source dir appear in the test output dir also, potentially overwriting test resources.
  • Type: boolean
  • Required: No
  • Default: false

<weaveWithAspectsInMainSourceFolder>

Flag to indicate if aspects in the the main source dirs should be a part of the compile process
  • Type: boolean
  • Required: No
  • Default: true

<XaddSerialVersionUID>

Causes the compiler to calculate and add the SerialVersionUID field to any type implementing java.io.Serializable that is affected by an aspect. The field is calculated based on the class before weaving has taken place.
  • Type: boolean
  • Required: No

<Xajruntimetarget>

(Experimental) Allows code to be generated that targets a 1.2 or a 1.5 level AspectJ runtime (default 1.5)
  • Type: java.lang.String
  • Required: No
  • Default: 1.5

<XhasMember>

Enables the compiler to support hasmethod(method_pattern) and hasfield(field_pattern) type patterns, but only within declare statements. It's experimental and undocumented because it may change, and because it doesn't yet take into account ITDs.
  • Type: boolean
  • Since: 1.3
  • Required: No

<Xjoinpoints>

supply a comma separated list of new joinpoints that can be identified by pointcuts. Values are: arrayconstruction, synchronization
  • Type: java.lang.String
  • Required: No

<Xlint>

Set default level for messages about potential programming mistakes in crosscutting code. {level} may be ignore, warning, or error. This overrides entries in org/aspectj/weaver/XlintDefault.properties from aspectjtools.jar.
  • Type: java.lang.String
  • Required: No

<Xlintfile>

Specify properties file to set levels for specific crosscutting messages. PropertyFile is a path to a Java .properties file that takes the same property names and values as org/aspectj/weaver/XlintDefault.properties from aspectjtools.jar, which it also overrides.
  • Type: java.io.File
  • Required: No

<xmlConfigured>

Parameter which indicates an XML file containing AspectJ weaving instructions. Assigning this plugin parameter adds the -xmlConfigured option to ajc.
See also: ajc reference
  • Type: java.io.File
  • Required: No

<XnoInline>

(Experimental) do not inline around advice
  • Type: boolean
  • Required: No

<XnotReweavable>

(Experimental) Create class files that can't be subsequently rewoven by AspectJ.
  • Type: boolean
  • Required: No

<Xreweavable>

(Experimental) runs weaver in reweavable mode which causes it to create woven classes that can be rewoven, subject to the restriction that on attempting a reweave all the types that advised the woven type must be accessible.
  • Type: boolean
  • Required: No

<XserializableAspects>

(Experimental) Normally it is an error to declare aspects java.io.Serializable. This option removes that restriction.
  • Type: boolean
  • Required: No

<Xset>

Allows the caller to provide additional arguments in a Map format. For example:
<configuration>
  <Xset>
    <overWeaving>true</overWeaving>
    <avoidFinal>false</avoidFinal>
  </Xset>
</configuration>
  • Type: java.util.Map<java.lang.String, java.lang.String>
  • Since: 1.5
  • Required: No

<XterminateAfterCompilation>

Causes compiler to terminate before weaving
  • Type: boolean
  • Required: No