I have been dealing with the problem for a day. I have a quite simple project so far, but still not able to configure AspectJ
My project structure looks as follows.
-- root
---- DesktopGUI
---- DataStore
---- localsettings
---- crosscuttingconcerns
I have defined all AspectJ
stuff in the cross-cutting-concerns
module.
My root pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<example.desktop.version>1.0-SNAPSHOT</example.desktop.version>
<example.desktop.settings.version>1.0-SNAPSHOT</example.desktop.settings.version>
<example.desktop.gui.version>1.0-SNAPSHOT</example.desktop.gui.version>
<aspectj.version>1.8.13</aspectj.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.solutions</groupId>
<artifactId>example</artifactId>
<packaging>pom</packaging>
<version>${example.desktop.version}</version>
<modules>
<module>DesktopGUI</module>
<module>DataStore</module>
<module>localsettings</module>
<module>crosscuttingconcerns</module>
</modules>
</project>
DesktopGUI pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>example</artifactId>
<groupId>com.example.solutions</groupId>
<version>${example.desktop.version}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>desktop-gui</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<mvvmfx.version>1.7.0</mvvmfx.version>
<jfoenix.version>8.0.1</jfoenix.version>
<jfxtrascontrols.version>8.0-r5</jfxtrascontrols.version>
<fontawesomefx.version>8.9</fontawesomefx.version>
<guice.version>4.1.0</guice.version>
</properties>
<!--Dependencies-->
<dependencies>
<!--DI, IoC Frameworks Dependencies-->
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-grapher</artifactId>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx</artifactId>
<version>${mvvmfx.version}</version>
</dependency>
<!--UI Dependencies-->
<dependency>
<groupId>com.jfoenix</groupId>
<artifactId>jfoenix</artifactId>
<version>${jfoenix.version}</version>
</dependency>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-controls</artifactId>
<version>${jfxtrascontrols.version}</version>
</dependency>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>${fontawesomefx.version}</version>
</dependency>
<dependency>
<groupId>de.saxsys</groupId>
<artifactId>mvvmfx-guice</artifactId>
<version>${mvvmfx.version}</version>
</dependency>
<!--Local project dependencies-->
<dependency>
<groupId>com.example.solutions</groupId>
<artifactId>local-settings</artifactId>
<version>${example.desktop.settings.version}</version>
</dependency>
<dependency>
<groupId>com.example.solutions</groupId>
<artifactId>cross-cutting-concerns</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Cross-Cutting-Concerns pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sto</artifactId>
<groupId>com.example.solutions</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<aspectj.version>1.8.13</aspectj.version>
<slf4f.version>1.8.0-beta0</slf4f.version>
</properties>
<artifactId>cross-cutting-concerns</artifactId>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4f.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4f.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
</dependencies>
</project>
I have defined my aspect as follows
@Aspect
public class MethodLogger {
private static Logger logger = LoggerFactory.getLogger(MethodLogger.class);
@Pointcut("execution(* *(..)) && @annotation(com.example.solutions.example.crosscuttingconcerns.annotation.LogMethodCall)")
public void logPointCut() {
}
@Around("logPointCut()")
public Object around(ProceedingJoinPoint point) {
try {
long start = System.currentTimeMillis();
Object result = point.proceed();
System.out.println("HELLOO");
logger.info("#%s(%s): %s in %[msec]s",
MethodSignature.class.cast(point.getSignature()).getMethod().getName(),
point.getArgs(),
result,
System.currentTimeMillis() - start
);
return result;
} catch (Throwable ex) {
return null;
}
}
}
And annotated my method like that
@Override
@LogMethodCall
public void startMvvmfx(Stage stage) throws Exception {
stage.setTitle(internalizationManager.getStringValue("titles", "main_app"));
stage.show();
stage.centerOnScreen();
}
This method is defined in the DesktopGUI
module
Annotation defined like that
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LogMethodCall {
}
It compiles without errors, but with a warning
Warning:(21, 0) ajc: advice defined in com.example.solutions.example.crosscuttingconcerns.aspect.MethodLogger has not been applied [Xlint:adviceDidNotMatch]
I have tried to add ApsectJ facets to my modules, but this still didn't help.
I think that the problem may be caused by multi module project structure.
Please help to solve this problem, I have not ideas what is wrong.
I have set Java Compiler
to Ajc
as well
Thanks