I\'d like to use AspectJ in Gradle project (it\'s not an Android project - just a simple Java app).
Here is how my build.gradle looks like:
apply plugin
A bit ugly, but short and does not require additional plugins or configurations. Works for me:
Add aspectjweaver
dependency ti Gradle build script. Then in the task you need it find the path to its jar and pass as javaagent
in jvmArgs
:
dependencies {
compile "org.aspectj:aspectjweaver:1.9.2"
}
test {
group 'verification'
doFirst {
def weaver = configurations.compile.find { it.name.contains("aspectjweaver") }
jvmArgs = jvmArgs << "-javaagent:$weaver"
}
}
Add aop.xml
file to the resources\META-INF\
folder with the specified Aspect class:
Example of an aspect:
package utils.listener
import org.aspectj.lang.JoinPoint
import org.aspectj.lang.annotation.*
import org.aspectj.lang.reflect.MethodSignature
@Aspect
@SuppressWarnings("unused")
public class StepListener {
/* === Pointcut bodies. Should be empty === */
@Pointcut("execution(* *(..))")
public void anyMethod() {
}
@Pointcut("@annotation(org.testng.annotations.BeforeSuite)")
public void withBeforeSuiteAnnotation() {
}
}