Using the AspectJ Compiler (ajc)
By default, IntelliJ IDEA uses the javac compiler. To use the AspectJ compiler ajc (instead of or in combination with javac ), you should make changes to corresponding IDE settings.
The ajc settings specified at the project level can be fine-tuned at the level of individual modules. AspectJ facets associated with the modules are used for that purpose.
Note that ajc is not bundled with IntelliJ IDEA and should be downloaded separately.
ajc is available as part of the AspectJ distribution that you can download from the AspectJ website.
Optimize compilation performance: Use ajc in combination with javac
IntelliJ IDEA lets you use ajc in combination with javac without the need to switch the compilers in the IDE settings.
First of all, you should select ajc as your project compiler (the Use compiler field on the Java Compiler page ).
If you want javac to be also used, turn on the Delegate to Javac option. If this option in on, the modules without aspects are compiled with javac (which is, generally, faster), and the modules that contain aspects are compiled with ajc. (If this option is off, ajc is used for all the modules in your project.)
You can fine-tune the distribution of tasks between the compilers ajc and javac at the level of individual modules. For modules that contain aspects only in the form of @Aspect
-annotated Java classes (in java files), you can specify that ajc should be used only for post-compile weaving. If you do so, javac will be used to compile all the source files, and then ajc will be applied to the compiled class files for weaving. As a result, the overall process (compilation + weaving), will take less time.
Provided that the Delegate to Javac option is on, the post-compile weaving mode for ajc is enabled by turning on the corresponding option in an AspectJ facet associated with a module.
Note that you shouldn't turn on this option for modules that contain code-style aspects (ones defined in .aj files).
Controlling the ajc aspectpath
You can control the ajc aspectpath
option separately for each of your modules, see Fine-tune the use of ajc at a module level.
The module aspectpath
may be set automatically as a result of importing an appropriately configured Maven project into IntelliJ IDEA.
Select ajc as the project compiler and specify its settings
In the Settings/Preferences dialog Ctrl+Alt+S, select .
From the Use compiler list, select Ajc.
If necessary, specify the bytecode versions. Roughly, these are the minimum target JVM versions.
Specify the path to the compiler in the Path to Ajc compiler field.
You can type the path in the field, or click and select the necessary file.
(The file that you want is aspectjtools.jar which is located in <AspectJ installation directory>\lib .)
If necessary, specify the command-line options to be passed to the compiler in the Command line parameters field.
You can type the parameters right in the field, or click to open the Command line parameters dialog where the text entry area is larger.
If you want to use javac to compile the modules that contain no aspects, select the Delegate to Javac checkbox.
Note that the distribution of tasks between ajc and javac can be fine-tuned at the level of individual modules.
Apply the changes and close the dialog.
Fine-tune the use of ajc at a module level
To be able to fine-tune the use of ajc at a module level, you should add an AspectJ facet to corresponding module or modules.
Once you've done that, you can specify that ajc should be used only for post-compile weaving. You can also specify the aspectpath
for the module.
Add an AspectJ facet to the module of interest. For corresponding instructions, see Add frameworks (facets).
From the main menu, select
.Under Compiler, select the Post-compile weave mode checkbox if you want to use ajc only to weave the compiled class files (the source code in this case is compiled with javac ).
To form the
aspectpath
for the module, use options Alt+Insert, Alt+Up/ Alt+Down, and Alt+Delete.Apply the changes and close the dialog.