4

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.

Adam Gent
  • 47,843
  • 23
  • 153
  • 203
  • I think it is valuable information to know that an advice does not match. Suppressing warnings is rarely a good idea. Imagine that suddenly the advice does match because your code base has changed. How will you be able to tell the difference? – kriegaex Dec 11 '14 at 14:40
  • @kriegaex I'm not sure you understand the problem. Of course its valuable but its a false warning as I'm not using that particular aspect and I know that I'm not using it. So now I have WARNING messages always in my build and thus have a higher probability of ignoring real WARNING messages. But to your point I do want to know about warnings for other aspects but you can only disable all of the warnings right now. Part of the problem is that `spring-aspects` includes aspects that are often irrelevant to projects. Not all projects use JPA. – Adam Gent Dec 11 '14 at 15:10

3 Answers3

3

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: I have just created a bug ticket because the parameter is undocumented.

Community
  • 1
  • 1
kriegaex
  • 63,017
  • 15
  • 111
  • 202
3

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

Geniy
  • 395
  • 3
  • 18
0

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.

Jose Luis Martin
  • 10,459
  • 1
  • 37
  • 38
  • I always thought aop.xml was for load time weaving and not compile time weaving. I shall look into that though. – Adam Gent Dec 11 '14 at 03:17
  • @AdamGent: You are right, *aop.xml* is only used for LTW. But it seems that José has updated his answer, I just read it now. It no longer contains any references to *aop.xml*. – kriegaex Dec 11 '14 at 14:38
  • Well the issue is the `spring-aspects` jar comes from maven so its unlikely I'm going to repackage it. I guess I'll just have to turn off the warning. I guess there is always unit tests. – Adam Gent Dec 11 '14 at 15:12
  • 1
    To my own surprise, there is an undocumented way to exclude aspects, simply by not *in*cluding them into an XML config file. See my answer about `-xmlConfigured`. – kriegaex Dec 12 '14 at 12:29