I have java library that I created which implements AOP using AspectJ runtime and AspectJ maven plugin. The AspectJ point cut is getting triggered when I add the annotations to the functions which are defined in the same library itself.
I want to use this library in another project so that I don't have to implement AOP in all of the projects that I will be using this library with regardless of their nature: native java app, spring or spring-boot apps. And regardless of they were using maven or gradle.
I tried to add my library to another gradle project spring configured with xml file. I added the annotation to function which is declared in the host app but the AOP doesn't get triggered, however when I call function from the library itself that has the annotation the AOP gets triggered even if I call it from host application.
Is there way to be able to do this or should the implementation of AOP be done in the same host project as well ?
For my example now the host application is using spring-framework and is built with gradle.
NOTE: the library is compiled and exported as jar using maven shade plugin
library POM.xml
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.9</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.10</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<complianceLevel>1.8</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Aspect class
@Aspect
public class TimerAspect {
@Around("@annotation(Timer) && execution(* *(..))")
public Object timerMethod(ProceedingJoinPoint joinPoint) throws Throwable{
...code
}
}
on the other application which uses gradle and spring-framework I just added the library as a dependency
implementation('com.exmple.library:aspetLib:1.0.0')
As I mentioned previously, the annotation is working fine if the functions are from the same library which has the AOP, however when I add this annotation to a function from the host app which uses spring the AOP doesn't trigger.