Maven:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.7</version>
</dependency>
Gradle:
groovy
implementation 'org.aspectj:aspectjrt:1.9.7'
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class ExecutionTimeAspect {
@Pointcut("execution(* com.example.mylibrary..*(..))")
public void anyMethod() {}
@Before("anyMethod()")
public void beforeMethodExecution() {
long startTime = System.currentTimeMillis();
}
@After("anyMethod()")
public void afterMethodExecution() {
long endTime = System.currentTimeMillis();
}
}
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
groovy
id 'aspectj' version '1.10.11'
-javaagent:/path/to/aspectjweaver.jar