How to build aspectj project using maven?

后端 未结 1 1983
滥情空心
滥情空心 2020-12-11 13:14

I have created a Aspectj Project in Eclipse ide but i need to build it using maven.

I have maven-aspectj plugin but don\'t know how to use it.

1条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 13:40

    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).

    1. Add a property to standardize the AspectJ version that you use:

      
          1.7.2
        ...
      
    2. Add the runtime dependency:

      
        org.aspectj
        aspectjrt
        ${aspectj.version}
      
      
    3. Add the AspectJ Maven plugin:

      
          org.codehaus.mojo
          aspectj-maven-plugin
          1.4
          
            
              
                compile
                test-compile
              
            
          
          
            
              org.aspectj
              aspectjrt
              ${aspectj.version}
            
            
              org.aspectj
              aspectjtools
              ${aspectj.version}
            
          
          
            1.7
            1.7
            true
          
        
      

    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. I'm blaming this (for now) on Eclipse overwriting class files or something, hence the forceAjcCompile.

    Additional things I did:

    1. Add src/main/aspects as an extra source directory (build-helper-maven-plugin plugin). Just because it looks good in 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)

    0 讨论(0)
提交回复
热议问题