Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging aspects with intellij

I'm experimenting with AspectJ and finding that intellij doen't seem to step into the @Around aspect. For example:

@Retention(RetentionPolicy.RUNTIME)
public @interface Test{}

@Aspect
public class TestAspect {
    @Around("execution(@aspects.Test * *(..))")
    public void around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("start1");

        point.proceed();

        System.out.println("end");
    }
}

@Data
public class Library {
    @Test
    public void forceError() {
        System.out.println("running");
    }

    private String foo;
}

And while I can compile and see my comments run in a unit test, I can't debug the aspect.

I've tried both aspect annotation based, and using the aspectJ .aj files with intellij to try and get the Around aspect to debug.

like image 863
devshorts Avatar asked Oct 26 '25 13:10

devshorts


1 Answers

I have the same issue.
My aspectj app works if I run the main class with gradle script(run task of application plugin, namely gradle clean build run -x test), but if I debugging the app by right-clicking Debug 'MyApp.main()' of the context menu of intellij idea, then the aop will not work.

And I find the solution: Setting ->Build,Execution,Deployment ->Build Tools ->Gradle ->Runner -> tick the option Delegate IDE build/run actions to gradle, then try to debug by right-clicking the Debug option of context menu of intellij idea and check the result.

This solution only works for gradle, and I have not tried it with maven.

like image 62
Iceberg Avatar answered Oct 28 '25 02:10

Iceberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!