Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure aspectj to get post-compile weaving (with maven)?

How to configure AspectJ in order to get post-compile weaving? I just replaced "compile" with "post-compile" in the plugin below: (needless to say that was unseccessful)

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

but I miss something as it gives the following error:

'post-compile' was specified in an execution, but not found in the plugin
like image 402
Sanyifejű Avatar asked Feb 10 '14 14:02

Sanyifejű


People also ask

What is AspectJ weaving?

Weaving in AspectJ Classes are defined using Java syntax. The weaving process consists of executing the aspect advice to produce only a set of generated classes that have the aspect implementation code woven into it.

What is AspectJ Maven plugin used for?

This plugin weaves AspectJ aspects into your classes using the AspectJ compiler ("ajc"). Typically, aspects are used in one of two ways within your Maven reactors: As part of a Single Project, implying aspects and code are defined within the same Maven project.

How does AspectJ works?

What AspectJ does is always pretty much the same: It modifies Java byte code by weaving aspect code into it. In case 1 you just get one set of class files directly from ajc . Case 2.1 creates additional, new class files. Case 2.2 just creates new byte code in memory directly in the JVM.


1 Answers

The JAR files containing the classes to weave must be listed as <dependencies/> in the Maven project and listed as <weaveDependencies/> in the <configuration> of the aspectj-maven-plugin. From 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>
like image 76
Steve Brewin Avatar answered Sep 21 '22 17:09

Steve Brewin