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

2.5k views Asked by At

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.

3

There are 3 answers

1
kriegaex On BEST ANSWER

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.

4
Jose Luis Martin On

Update

AFAIK, you can only add external aspects to ajc with -aspectpath that will include all aspects in the jars, so there is no way to add a jar with aspects but excluding some one unless you unzip, delete and create a new jar.

0
Geniy On

Just to add, there is possibility to change log level for adviceDidNotMatch for aspectj-maven-plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <artifactId>1.5</artifactId>
    <configuration>
          <Xlint>adviceDidNotMatch=error,noGuardForLazyTjp=ignore</Xlint>
    </configuration>
</plugin>

Possible values: ignore/warning/error

related jira: https://jira.codehaus.org/browse/MASPECTJ-126