maven - 如何配置aspectj以获得编译后编织(使用maven)?

标签 maven configuration pom.xml aspectj compile-time-weaving

如何配置 AspectJ 以获得编译后编织?我刚刚在下面的插件中将“compile”替换为“post-compile”:(不用说这是不成功的)

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.5</version>
    <configuration>
        <complianceLevel>1.6</complianceLevel>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>post-compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

但我错过了一些东西,因为它给出了以下错误:

'post-compile' was specified in an execution, but not found in the plugin

最佳答案

包含要编织的类的 JAR 文件必须列为 <dependencies/>在 Maven 项目中并列为 <weaveDependencies/><configuration>的aspectj-maven-插件。来自 http://www.mojohaus.org/aspectj-maven-plugin/examples/weaveJars.html :

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.8.13</version>
    </dependency>

     <dependency>
      <groupId>org.agroup</groupId>
      <artifactId>to-weave</artifactId>
      <version>1.0</version>
    </dependency>

    <dependency>
      <groupId>org.anothergroup</groupId>
      <artifactId>gen</artifactId>
      <version>1.0</version>
    </dependency>
    ...
  </dependencies>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.11</version>
        <configuration>
          <weaveDependencies>
            <weaveDependency>
              <groupId>org.agroup</groupId>
              <artifactId>to-weave</artifactId>
            </weaveDependency>
            <weaveDependency>
              <groupId>org.anothergroup</groupId>
              <artifactId>gen</artifactId>
            </weaveDependency>
          </weaveDependencies>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  <build>
  ...
</project>

关于maven - 如何配置aspectj以获得编译后编织(使用maven)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21679502/

相关文章:

java - 无法使用 Ansible 在远程主机中使用 Maven 进行打包

maven - 如何从 Maven 依赖项生成 JBoss jboss-deployment-structure

maven - 如何在 Intellij Idea 13 中将 Maven 项目部署到 Glassfish Server

asp.net - 如何更改 ASP.NET 配置工具连接字符串

java - 无论如何要排除从父 POM 继承的 Artifact ?

maven - maven 会自动下载 Artifact 依赖项吗?

unit-testing - WebStorm 运行所有 dart 单元测试

python2.5说未找到平台相关库

java - Maven javafx 插件 : generate MANIFEST

java - 项目间依赖关系和项目之间的文件共享