AspectJ编织Maven模块 [英] AspectJ weaving maven modules
问题描述
我有一个包含多个Maven模块的项目,其中一个包含我的方面.我该如何考虑各个方面并编织多个Maven模块? AspectJ Maven插件的文档很少,并且找不到很多示例.
I have a project that has multiple maven modules, one of which, contains my aspects. How can I take the aspects and weave multiple maven modules? The documentation for the AspectJ Maven plugin is a little sparse and haven't been able to find many examples.
我曾尝试将Aspectj插件放在父pom中,但似乎没有对它下面的模块应用建议.
I have tried putting the aspectj plugin in the parent pom but it doesn't seem to apply the advice for the modules underneath it.
我也尝试指定AspectsDirectory属性,但似乎没有任何影响.也许我做错了吗?
I also tried specifying the aspectsDirectory property but it didn't seem to have any affect. Perhaps I did it wrong?
推荐答案
我认为该机制在此页面上已得到很好的解释:
I think the mechanism is explained pretty well on this page:
基本上:
您将所有方面放入一个项目中,使用aspectj-maven-plugin对其进行编译,将该项目的依赖项添加到您要编织的所有项目中,并将此配置添加到编织的项目中:
You put all your aspects in one project, compile it using the aspectj-maven-plugin, add a dependency to this project to all projects you want to weave and also add this config to the woven projects:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>your.aspects.groupId</groupId>
<artifactId>your.aspects.artifactId</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
丑陋的部分是:您需要将此配置添加到每个项目,所以一种可能性是使用父pom.不幸的是,它必须与Aspects项目处于同一级别(因为pom不能在其下面定义对项目的依赖),所以您会遇到类似的情况
The ugly part is: you need to add this configuration to every project, so one possibility would be to use a parent pom. Unfortunately, it would have to be at the same level as the aspects project (because a pom can't define a dependency to a project below it), so you'd have something like this
------- root --------
/ \
aspects -------- java-parent ----
/ / | | \
java1 java2 java3 java4 java5
甚至是这样
------- root ---------
/ \
aspect-parent --- java-parent ---
/ \ / | | \
aspects1 aspects2 java1 java2 java3 java4
您要将<dependency>
和Aspectj插件配置都添加到java-parent项目的pom中
You'd add both the <dependency>
and the aspectj plugin configuration to the pom of the java-parent project
这篇关于AspectJ编织Maven模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!