6

如何配置 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
4

1 回答 1

5

包含要编织的类的 JAR 文件必须<dependencies/>在 Maven 项目中列出,并<weaveDependencies/><configuration>aspectj-maven-plugin 中列出。来自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>
于 2016-05-13T15:33:07.310 回答