Search code examples
springmavenaspectjspring-aspects

How do you ignore AspectJ compiler warnings for certain aspects with Maven


If you use the AspectJ compiler with an Aspect library such as Springs and you do not have any classes that match a particular Aspect you get:

[WARNING] advice defined in org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect has not been applied [Xlint:adviceDidNotMatch] 

But for this particular project I don't need this aspect as well as some other aspects.

It seems you can configure the warnings with -Xlint but it looks like you can only turn off all the warning for advice that doesn't match (adviceDidNotMatch=ignore). What I really want to do is exclude certain Aspects such as org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect. I can't seem to find an example of excluding an aspect.


Solution

  • If you are ready to list each single aspect to be used in some kind of whitelist, you can use

    ajc -xmlConfigured myConfig.xml ...
    

    or the corresponding AspectJ Maven Plugin parameter. Why this is not listed in the ajc usage help, I have no idea. I have never used this option before, but just tested it now and can confirm that it works. It should be in ajc since 1.6.9 and in AspectJ Maven since 1.5.

    See also this answer for more information and a sample XML file. A minimal sample is also listed here.

    Please note: The option and XML file name have to be explicitly specified. Unlike aop.xml in LTW mode there is no file with a magic name to be picked up automatically for CTW. This fact was mentioned by AspectJ maintainer Andy Clement here.

    Update: AJC option -xmlConfigured is now documented here.