【问题标题】:How to configure aspectj to get post-compile weaving (with maven)?如何配置aspectj以获得编译后编织(使用maven)?
【发布时间】:2014-03-07 22:04:28
【问题描述】:

如何配置 AspectJ 以获得编译后编织?我只是在下面的插件中将“编译”替换为“后编译”:(不用说这是不安全的)

<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

【问题讨论】:

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


【解决方案1】:

包含要编织的类的 JAR 文件必须在 Maven 项目中列为 &lt;dependencies/&gt;,并在 aspectj-maven-plugin 的 &lt;configuration&gt; 中列为 &lt;weaveDependencies/&gt;。来自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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 2013-03-18
    • 2012-11-21
    相关资源
    最近更新 更多