Fork me on GitHub

Weaving already compiled JAR artifacts

AspectJ gives a possibility to weave already compiled classes in a JAR file. In order to do this with Mojo's AspectJ Maven Plugin you need do setup all the JAR files you would like to weave in the plugin configuration as shown below.

Note: The artifacts you reference must exist as dependencies in the project.

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.9.7</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.15.0</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>