简体   繁体   English

如何使用Maven构建AspectJ项目?

[英]How to build aspectj project using maven?

I have created a Aspectj Project in Eclipse ide but i need to build it using maven. 我已经在Eclipse IDE中创建了一个Aspectj项目,但是我需要使用Maven来构建它。

I have maven-aspectj plugin but don't know how to use it. 我有maven-aspectj插件,但不知道如何使用它。

Below are the steps that I followed to get this working. 以下是我执行此步骤的步骤。 This gave me compile-time weaving . 这给了我编译时的编织 If you need other strategies, clearly you need another approach (such as Spring AOP for runtime AOP proxies). 如果您需要其他策略,那么显然您需要另一种方法(例如用于运行时AOP代理的Spring AOP )。

  1. Add a property to standardize the AspectJ version that you use: 添加一个属性以标准化您使用的AspectJ版本:

     <properties> <aspectj.version>1.7.2</aspectj.version> ... 
  2. Add the runtime dependency: 添加运行时依赖项:

     <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectj.version}</version> </dependency> 
  3. Add the AspectJ Maven plugin: 添加AspectJ Maven插件:

     <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectj.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjtools</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> <configuration> <source>1.7</source> <target>1.7</target> <forceAjcCompile>true</forceAjcCompile> </configuration> </plugin> 

I'm not sure if forceAjcCompile makes a lot of sense, really, but I've seen some cases where the aspects weren't consistently applied. 我不确定forceAjcCompile是否真的有意义,但是我发现有些情况下各个方面的应用不一致。 I'm blaming this (for now) on Eclipse overwriting class files or something, hence the forceAjcCompile . 我现在(现在)将其归咎于Eclipse覆盖类文件之类的东西,因此是forceAjcCompile

Additional things I did: 我做的其他事情:

  1. Add src/main/aspects as an extra source directory ( build-helper-maven-plugin plugin). 添加src/main/aspects作为额外的源目录( build-helper-maven-plugin插件)。 Just because it looks good in Eclipse 只是因为它在Eclipse中看起来不错
  2. Add a pluginExecution / pluginExecutionFilter for the AspectJ plugin ( lifecycle-mapping plugin ) and set it to execute and runOnIncremental , so that also aspects are (re-)applied when coding and testing in Eclipse (using m2e) 为AspectJ插件( lifecycle-mapping插件 )添加pluginExecution / pluginExecutionFilter并将其设置为executerunOnIncremental ,以便在Eclipse中进行编码和测试(使用m2e)时也可以(重新)应用方面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM