mohammad_1m2
mohammad_1m2

Reputation: 1611

AspectJ not working in maven project in IntelliJ

I have maven project that use aspectJ for auditing. I'm use Intellij idea. Here is my plugin config in pom file:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.7</version>
                <configuration>
                    <showWeaveInfo>true</showWeaveInfo>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <Xlint>ignore</Xlint>
                    <complianceLevel>${java.version}</complianceLevel>
                    <encoding>UTF-8</encoding>
                    <verbose>true</verbose>
                </configuration>
                <executions>
                    <execution>
                        <!-- IMPORTANT -->
                        <phase>process-sources</phase>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>1.8.10</version>
                    </dependency>
                </dependencies>
</plugin>

When I clean package the aspectJ plugin says:

Join point 'method-execution(java.util.List com.test.getHistories(java.lang.String, java.lang.String))' in Type 'com.test.HistoryService' (HistoryService.java:18) advised by around advice from 'com.test.aspects.AuditLoggerAspect' (AuditLoggerAspect.java:88)

Join point 'method-execution(java.lang.String com.test.getString(int, java.lang.Object))' in Type 'com.test' (AspectTest.java:14) advised by around advice from 'com.test.AuditLoggerAspect' (AuditLoggerAspect.class(from AuditLoggerAspect.java))

This app packaging is WAR and i want to deploy it on Weblogic. When I deploy it or run test the aspect not work. Why?

I test this aspect and maven plugin config in Java App and it's work good.

Upvotes: 0

Views: 1881

Answers (1)

mohammad_1m2
mohammad_1m2

Reputation: 1611

When I clean and package the project, the maven-compiler-plugin recompiles the projects after aspectj-compiler-plugin compiled it. So the compiled aspects are removed.

I added the below config to maven-compiler-plugin to solve it:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
        <!-- IMPORTANT -->
        <useIncrementalCompilation>false</useIncrementalCompilation>
    </configuration>
</plugin>

Upvotes: 1

Related Questions