I meet some problems about the way of using aspectj-maven-plugin and aspectj.
First: I create ProjectA. It will be a 'compiled aspect' jar to intercept some functions of Logback and it is a public common jar so that other projects can use it.
I add below code in ProjectA's pom:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>xxx</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.8</source>
<target>1.8</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.8</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<weaveDependencies>
<weaveDependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.9.7</version>
</dependency>
</dependencies>
</plugin>
And then I finish the specific intercept code like @Around("within(ch.qos.logback.classic.Logger+)
After above, I package ProjectA as a jar.
Second: I create ProjectB. I apply ProjectA's jar in ProjectB,so I can intercept ProjectB' log produced by its logback with ProjectA.
I add ProjectA and in ProjectB' pom.xml
<dependency>
<groupId>xxx</groupId>
<artifactId>ProjectA</artifactId>
<version>xxx</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.8</source>
<target>1.8</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.8</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>xxx</groupId>
<artifactId>ProjectA</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.9.7</version>
</dependency>
</dependencies>
</plugin>
I package ProjectB with maven.I expect to see the wovend Logback
code in ProjectB's output directory,but dont success.
Question During the process above,I refer to AspectJ: How to weave an aspect library into a Java project. I want to know
- is there something wrong with my idea?
- why I faild and the correct way to achieve my goal.
Pls help me~~~
Update on 11/1
I think I should redescribe the idea about the ProjectA. It is used by other project to track trace like Skywalking. The difference is that I choose Aspect CTW to realize the function. In ProjectA(a multi-module project), there are different module like mysql-module\logback-module....to intercept specific function by using @Aspect(execution) and then weave 'log' code. One module may have different VERSION like mysql-module-8.0 \ mysql-module-5.7 because the api function may change with version upgrading.
The other projects which will use ProjectA are based on Springboot. Now,I apply ProjectA in ProjectB,I code the ProjectB'pom.xml like above. If I directly use compiled ProjectA.jar in ProjectB ,it may cause VERSION CONFLICT. I dont want to use '' because there are many module in Project A and one module may have several VERSION.
So I want to try this way:
- I code the modules with @AspectJ in ProjectA.
- I have tried to solve the VERSION CONFLICT by develop aspectj-maven-plugin by judging ProjectA's and ProjectB's artifactId version.
- The most important thing is that I want to use aspectj-maven-plugin to compile and package in ProjectB . I expect that weaving by 'ProjectA’Class with @Aspect' happens during ProjectB's compile and package process. Because collegues used to run Springboot'Main Function directly in dev environment rather than deploy in a external Tomcat. By doing the 3 step,I can avoid VERSION CONFLICT in dev environment . And in proc_environment,I use a tomcat to deploy so that I can use aspect-maven-plugin to weave code.