Fork me on GitHub

Using sources

Since version 1.4 this plugin has a much stronger way of defining the Java sources, their includes and excludes. The plugin makes use of the Plexus Scanner (i.e. the DirectoryScanner implementation), an advanced implementation which covers most needs regarding source selection. If you don't want to use any sourceDirectory, Maven 3 users can just add an empty sources element (i.e. <sources/>). If you're a Maven 2 user you have to specify an empty source element (i.e. <sources><source/></sources>).

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.9.7</version>
    </dependency>
    ...
  </dependencies>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.15.0</version>
        <configuration>
          <sources>
            <source>
              <basedir>src/main/java</basedir>
              <includes>
                <include>**/TransationAspect.java</include>
                <include>**/SecurityAspect.aj</include>
              </includes>
              <excludes>
                <exclude>**/logging/*.aj</exclude>
              </excludes>
            </source>
          </sources>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  <build>
  ...
</project>

Using includes/excludes

The AspectJ Plugin will by default add all .java and .aj files in the project source directories. Below you will find an example of how to add include/exclude filtering on top of that.

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.9.7</version>
    </dependency>
    ...
  </dependencies>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.15.0</version>
        <configuration>
          <includes>
            <include>**/TransationAspect.java</include>
            <include>**/SecurityAspect.aj</include>
          </includes>
          <excludes>
            <exclude>**/logging/*.aj</exclude>
          </excludes>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  <build>
  ...
</project>