Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

AspectJMaven/ant

AspectJ develops some Ant tasks, to call AspectJ compiler from inside an Ant build, and Maven supports calling Ant during it's build.

So, it's possible to use this technique to call AspectJ inside Maven, which offers a few advantages :

  • Since Ant tasks are developed by AspectJ developers, they are updated with each new feature in AspectJ
  • It gives fine control over the AspectJ compiler.

But unfortunately, also gives a disadvantage : being on your own, you don't have much support from Maven, so it's quite tricky to use aspect libraries.

An example of using Ant follows :


<build>
 [...]
 <plugins>
  <!-- Stop javac from compiling -->
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>        
    <configuration>
        <excludes>
            <exclude>**/*.*</exclude>
        </excludes>
    </configuration>
  </plugin>
  <!-- Configure ant-run -->
  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <dependencies>
      <!-- We need this trick, cause AJC needs a complete JDK -->
      <dependency>
        <groupId>sun.jdk</groupId>
        <artifactId>tools</artifactId>
        <version>1.5.0</version>
        <scope>system</scope>
        <systemPath>${java.home}/../lib/tools.jar</systemPath>
      </dependency>
      <!-- Depend on the AspectJ version you need -->
      <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.6.0</version>
      </dependency>
    </dependencies>

    <executions>
      <execution>
        <phase>compile</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>
            <!-- Here is the ANT snippet -->
            <taskdef
              resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"
              classpathref="maven.plugin.classpath" />
            <!-- You can use all Ant task options here -->
            <iajc
              srcDir="src/main/java"
              destDir="target/classes"
              classpathRef="maven.compile.classpath">
            </iajc>

          </tasks>
        </configuration>
   [...]
</build>

Back to the top