Search code examples
javaintellij-ideaaspectjaspectj-maven-plugin

IntelliJ ApectJ post-compile time weaving


I have the following aspect:

@Aspect
public class DefaultStringAspect {

    @Around(value = "execution(* org.apache.commons.lang3.StringUtils.defaultString(..))")
    public Object defaultString(ProceedingJoinPoint pjp) {
        return "DEF";
    }  
}

This aspect is applied to a classpath library. It works fine with maven configuration below:

           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                ..
                <configuration>
                   ..
                    <weaveDependencies>
                        <weaveDependency>
                            <groupId>org.apache.commons</groupId>
                            <artifactId>commons-lang3</artifactId>
                        </weaveDependency>
                    </weaveDependencies>
                </configuration>
            </plugin>

When I try to build the project from IntelliJ IDEA, the aspect is not applied. The aspect itself is compiled, but woven dependencies are not. I've tried to adjust ajc command line options taken from maven's debug output and add them to IntelliJ:

-showWeaveInfo -verbose -classpath ... -inpath ... -d ...

but this didn't work for me. Any other ideas how to force IntelliJ to use the same ajc configuration as maven?


Solution

  • Delegate IDE build/run actions to Maven as a workaround (File | Settings | Build, Execution, Deployment | Build Tools | Maven | Runner):

    delegate