AspectJ and Maven configuration

Here is a maven configuration for AspectJ weaving. We use here the “codehaus” maven plugin for AOP Weaving with AspectJ 1.6.x and Java 1.6 versions.

maven dependencies

<dependencies>
...
  <dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.6.11</version>
  </dependency>
...
  <dependency>
    <groupId>my-artifact-to-weave.groupId<groupId>
    <artifactId>my-artifact-to-weave.artifactId</artifactId>
    <version>my-artifact-to-weave.version</version>
  </dependency>
...
</dependencies>

maven compiler plugin configuration

In order to use annotated based pointcuts and advices definitions.

<build>
  <plugins>
    ...
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.5.1</version>
      <configuration>
        <target>1.6</target>
        <source>1.6</source>
      </configuration>
    </plugin>
    ...
  </plugins>
</build>

maven AspectJ plugin configuration

<build>
  <plugins>
    ...
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>aspectj-maven-plugin</artifactId>
      <version>1.4</version>
      <configuration>
        <weaveDependencies>
          <weaveDependency>
            <groupId>my-artifact-to-weave.groupId<groupId>
            <artifactId>my-artifact-to-weave.artifactId</artifactId>
          </weaveDependency>
        </weaveDependencies>
      </configuration>
      <executions>
        <execution>
          <id>compile</id>
          <configuration>
            <source>1.6</source>
          </configuration>
          <goals>
            <goal>compile</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
</build>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s