</para>
</sect2>
- </sect1>
- <sect1 id="antTasks-maven" xreflabel="Maven support">
- <title>Maven support</title>
- <para>
- 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
- <ulink url="http://maven.apache.org">http://maven.apache.org</ulink>.
- </para>
- <sect2 id="antTasks-maven-plugin" xreflabel="Sample Maven plugin">
- <title>Sample Maven plugin</title>
- <para>
- To integrate AspectJ requires writing a Maven plugin and
- installing the AspectJ libraries in the local Maven
- repositories directory.
- </para>
- <para>
- 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:
- </para>
- <programlisting>
- <![CDATA[
- maven aspectj
-]]>
- </programlisting>
- <para>
- 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.)
- </para>
- <programlisting>
- <![CDATA[
-----plugins
- |---maven-aspectj-plugin-1.1
- | plugin.jelly
- | project.properties
- | project.xml
- |---META-INF
- INDEX.LIST
- LICENSE.txt
- MANIFEST.MF
-]]>
- </programlisting>
- <para>
- Below is a <literal>plugin.jelly</literal>
- script that defines the
- Ant calls. The script uses XML namespace prefixes,
- so find the start of the Ant compiler call
- at <literal><ant:iajc ...</literal>.
- Note that it uses the existing rule for defining
- <literal>aspectSourcesPresent</literal>.
- </para>
- <programlisting>
- <![CDATA[
-<?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>
-]]>
- </programlisting>
- <para>
- In this example, no special options
- are supported, but nicely enough the script can read the
- library jars from the plugin dependency path:
- </para>
- <programlisting>
- <![CDATA[
- <ant:pathelement path="${plugin.getDependencyPath('aspectj:aspectjrt')}"/>
-]]>
- </programlisting>
- <para>
- The plugin dependency path and the filenames of the library
- jars are defined in the plugin
- <literal>project.xml</literal> file.
- Below are the relevant definitions:
- </para>
- <programlisting>
- <![CDATA[
-<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>
-]]>
- </programlisting>
- <para>
- 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:
- </para>
- <programlisting>
- <![CDATA[
-|---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
-]]>
- </programlisting>
- <para>
- 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.
- </para>
- </sect2>
</sect1>
<!-- . . . . . . . . . . . . . . . . . . . . . . . . . . . problems -->