Fork me on GitHub

Using includes/excludes

Using sources

With AspectJ Maven Plugin, if the default setting it not what you need, you can define the Java and AspectJ sources, their includes and excludes.

The plugin makes use of the Plexus Scanner, i.e. the DirectoryScanner implementation, an advanced implementation covering most needs regarding source selection.

If you do not wish to use any source directory at all, e.g. in a plugin execution only doing binary weaving, you can just add an empty sources tag, i.e. <sources/> (Maven 3 style) or <sources><source/></sources> (Maven 2 style).

<project>
  <!-- ... -->
  <dependencies>
    <!-- ... -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>${aspectjVersion}</version>
    </dependency>
    <!-- ... -->
  </dependencies>
  <!-- ... -->
  <build>
    <plugins>
      <plugin>
        <groupId>${project.groupId}</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>${project.version}</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

AspectJ Maven Plugin will by default add all .java and .aj files in the project source directories. Below, you 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>${aspectjVersion}</version>
    </dependency>
    <!-- ... -->
  </dependencies>
  <!-- ... -->
  <build>
    <plugins>
      <plugin>
        <groupId>${project.groupId}</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>${project.version}</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>