Maven is a project-based build system used by Apache and others to integrate many open-source projects. They have a plugin to support AspectJ 1.0, and we plan to help them support AspectJ 1.1. In the meantime, this describes how to upgrade an existing Maven environment to use the AspectJ 1.1 compiler. It was verified on a 1.0-beta10-SNAPSHOT release. For more information on Maven, see http://maven.apache.org.
To integrate AspectJ requires writing a Maven plugin and installing the AspectJ libraries in the local Maven repositories directory.
The Maven plugin defines an "aspectj" goal; given a project with directories "src" and "aspectsrc", the plugin will compile everything using AspectJ. To use the plugin, request the aspectj goal in your project:
maven aspectj
The plugin is mainly a Jelly script that specifies Ant scriptlets to run when building with AspectJ. To create your own, start with the files from the Maven support for AspectJ 1.0. (Unfortunately, their plugin version is 1.1. If you want to continue using the old version, copy the files and use a different version number than 1.1 in the examples below.)
----plugins |---maven-aspectj-plugin-1.1 | plugin.jelly | project.properties | project.xml |---META-INF INDEX.LIST LICENSE.txt MANIFEST.MF
Below is a plugin.jelly script that defines the Ant calls. The script uses XML namespace prefixes, so find the start of the Ant compiler call at <ant:iajc .... Note that it uses the existing rule for defining aspectSourcesPresent.
<?xml version="1.0"?> <project xmlns:j="jelly:core" xmlns:ant="jelly:ant" xmlns:util="jelly:util"> <goal name="aspectj" description="Compile code with AspectJ" prereqs="aspectj:compile"/> <goal name="aspectj:compile" description="Compile code with AspectJ"> <j:if test="${sourcesPresent == 'true'}"> <ant:available property="aspectSourcesPresent" file="${pom.build.aspectSourceDirectory}"/> <ant:uptodate property="aspectj.compile.notRequired" targetfile="${maven.build.dir}/${maven.final.name}.jar"> <ant:srcfiles dir="${pom.build.sourceDirectory}"/> <j:if test="${aspectSourcesPresent == 'true'}"> <ant:srcfiles dir="${pom.build.aspectSourceDirectory}"/> </j:if> </ant:uptodate> <j:set var="aspectjCompileNotRequired" value="${aspectj.compile.notRequired}"/> <j:if test="${aspectjCompileNotRequired == null}"> <ant:taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"> <ant:classpath> <ant:pathelement path="${plugin.getDependencyPath('aspectj:aspectjtools')}"/> </ant:classpath> </ant:taskdef> <!-- fork to avoid BCEL library version conflict with maven --> <ant:iajc destdir="${maven.build.dest}" debug="${maven.compile.debug}" fork="true"> <ant:forkclasspath> <ant:pathelement path="${plugin.getDependencyPath('aspectj:aspectjtools')}"/> </ant:forkclasspath> <ant:sourceroots> <ant:path refid="maven.compile.src.set"/> <ant:pathelement location="${pom.build.aspectSourceDirectory}"/> </ant:sourceroots> <ant:classpath> <ant:path refid="maven.dependency.classpath"/> <ant:pathelement path="${plugin.getDependencyPath('aspectj:aspectjrt')}"/> </ant:classpath> </ant:iajc> </j:if> </j:if> </goal> </project>
In this example, no special options are supported, but nicely enough the script can read the library jars from the plugin dependency path:
<ant:pathelement path="${plugin.getDependencyPath('aspectj:aspectjrt')}"/>
The plugin dependency path and the filenames of the library jars are defined in the plugin project.xml file. Below are the relevant definitions:
<project> <extend>${basedir}/../project.xml</extend> <pomVersion>3</pomVersion> <id>maven-aspectj-plugin</id> ... <dependencies> <dependency> <id>aspectj:aspectjtools</id> <version>1.1</version> <properties> <classloader>root</classloader> </properties> </dependency> <dependency> <id>aspectj:aspectjrt</id> <version>1.1</version> <properties> <classloader>root</classloader> </properties> </dependency> </dependencies> ... </project>
So the actual paths are calculated from the dependencies, which resolve to the local repository directory of your Maven installation. After you update the Jelly script, manually rename and copy the AspectJ 1.1 libraries to your directory:
|---repository |---aspectj | |---jars | aspectj-ant-1.0.6.jar | aspectj-ant-1.0.6.jar.md5 | aspectj-tools-1.0.6.jar | aspectj-tools-1.0.6.jar.md5 | aspectjrt-1.0.6.jar | aspectjrt-1.0.6.jar.md5 | aspectjrt-1.1.jar # add manually | aspectjtools-1.1.jar # add manually
That should be it. Remember to go through the files for any version or library jar name changes. Again, long-term, we hope to the Maven folks can have an official version of the AspectJ plugin which supports both AspectJ 1.0 and 1.1.