Fork me on GitHub

Introduction

AspectJ Maven Plugin

This plugin weaves AspectJ aspects into your classes using the AspectJ compiler ajc. Typically, aspects are used in one of two ways within your Maven reactors:

  • As part of a single project, implying aspects and code are defined within the same Maven project. This is the simplest approach to start out with. Feel free to examine the basic usage example to better understand single-project use.

  • As part of a multi-module Maven reactor where one or more modules contain aspects and other modules within the Maven reactor contain code affected ("woven") by those aspects. This is a more complex and powerful approach, best suited when several Maven projects should be woven by a common set of aspects. The AspectJ in a multi-module reactor example contains a basic walk-through of this approach.

AspectJ Maven Plugin delegates most of its work to the AspectJ compiler ajc or documentation creator ajdoc included within the plugin. Refer to the AspectJ website for information and documentation about AspectJ itself.

Plugin, AspectJ and Java version compatibility

AspectJ Maven Plugin itself only requires Java 8 during build time and by default depends on the relatively old AspectJ version 1.9.7, because it contains the last AspectJ compiler version capable of running on Java 8, even though it can compile up to source/target Java 16.

Chances are, that you need support for more recent source/target versions, e.g. Java 17 or 21. Or maybe, you simply wish to use the most recent AspectJ features and bugfixes. In that case, it is easy to change the AspectJ version used by this plugin by simple configuration. That might, however, require you to also run the plugin on a JDK more recent than 8. For example, AspectJ 1.9.8+ requires a Java 11 runtime, AspectJ 1.9.21+ requires Java 17.

Good news: All more recent AspectJ versions can still compile to lower source/target levels, i.e. your compiled programs still run on older Java versions, if you wish.

So if you wish to upgrade to a newer (or downgrade to a lower) AspectJ version, simply override the default aspectjtools plugin dependency. You have maximum flexibility, depending on your use case. You only ever need to upgrade the plugin, if you need a new feature or bugfix of the plugin itself.