<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.10</version>
<configuration>
<verbose>true</verbose>
<showWeaveInfo>true</showWeaveInfo>
<source>1.8</source>
<target>1.8</target>
<complianceLevel>1.8</complianceLevel>
<verbose>false</verbose>
<Xlint>ignore</Xlint>
<outxml>true</outxml>
<forceAjcCompile>true</forceAjcCompile>
<reweavable>false</reweavable>
<!-- this is important: start-->
<sources/>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<!-- this is important: end-->
</configuration>
<executions>
<execution>
<!-- The right phase is very important! Compile and weave aspects after all classes compiled by javac -->
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies>
</plugin>
According to the standard, the aspectj-maven-plugin provides weaving during compilation. But Lombok is a compile-time preprocessor. Therefore, in order for the weaving to occur after the code is compiled, the following is necessary.
In the plugin:
<forceAjcCompile>true</forceAjcCompile> и <sources/>
You also need to turn off the autobuild in Intellij Idea. And execute the following command:
mvn clean compile install -Pdev
Only as a result of this command, the necessary weaving begins! Because of the "install" command.
Tell me, please, why is the weaving happening only thanks to this command? Or are other command options possible, for example, so that tests are not pulled up, etc.?
the statement above is not correct from AspectJ perspective. There are three (if do not pay attention to
Spring API) modes to use AspectJ:native aspectJ (.aj) syntaxfiles or useinter-type declarationsjavacand after thatajcprocesses resulting classes - that is your case cause you have specified<sources/>-javaagentin JVM arguments or have specialised classloadertechnically, from
maven lifecycleperspective everything should work fine in case of post-compile time weaving, however IDEs typically do not triggermaven lifecyclewhen you are pressing green arrow near#mainor@Testmethod, instead of that IDEs try to analyse project object model (pom) and make some assumptions about target classpath and dependencies. Unfortunately, IDEs do not support all maven plugins and that is the main reason why sometimes something does not work as expected (for example, IntelliJ do not support code generators likeOpenAPIorAxis2, that is why we place that stuff into separate maven modules/projects and runmvn install). It seems that purpose of yourmvn ... installis to place correct jar into.m2/repositoryand give IDE a chance to pick up that jar.UPD. Some explanations....
Let consider a case when we need to run individual unit test, from
mavenperspective that would be something like:and
mavenwill launch it without facing any difficulties, because beforeteststep it will startcompileandtest-compilesteps, wherejavacandajcdo the required job. Unfortunately, from developer perspective the maven command mentioned above "takes ages", and that is the reason why IDE tries to optimise that process by compiling only changed classes, unfortunately, if IDE does not support AspectJ (for example, IntelliJ CE does not) or does not recognise maven configuration it has no chance to produce expected output.Your case is even more complicated because you are using
lombok, which is not compatible withajc(or vice versa), so to produce correct classes you need first compile sources byjavacand then postprocess output byajc.If your goal is to somehow simplify IDE setup for particular project I would recommend the following: