Hi,
I've recently been trying out the Macker tool (http://innig.net/macker)
to enforce architectural rules in a project of mine. I did some
searching in this mailing list as well as Google if there was a way to
run Macker with Maven 2, but only found questions from others asking how
this should be done. The existing maven-macker-plugin is for Maven 1,
though I have seen a message that there apparently is a Maven 2 plugin
in development.
Anyway, I have been fiddling around a bit and found a way to run Macker
in Maven 2 until a proper plugin is available, which I thought I'd share
here for anyone interested. As I still consider myself as a Maven 2
newbie, I would appreciate any feedback on this solution, if it seems
reasonable at all. This is the first time I use the antrun plugin, and I
have no experience using Ant before at all.
The description below is for a simple single project following the
directory structure expected as default by Maven 2. It should however be
simple to adapt it. This is going to be a bit lengthy, so bring a sandwich.
1. In your POM:
<build>
...
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>1.1</version>
<configuration>
<tasks>
<ant antfile="${basedir}/build.xml"
inheritRefs="true">
<target name="macker"/>
</ant>
</tasks>
</configuration>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-antlr</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlrall</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<artifactId>macker</artifactId>
<groupId>innig</groupId>
<version>0.4.2</version>
</dependency>
<dependency>
<artifactId>innig-util</artifactId>
<groupId>innig</groupId>
<version>0.4.2</version>
</dependency>
<dependency>
<artifactId>jakarta-regexp</artifactId>
<groupId>jakarta-regexp</groupId>
<version>1.4</version>
</dependency>
<dependency>
<artifactId>bcel</artifactId>
<groupId>bcel</groupId>
<version>5.1</version>
</dependency>
<dependency>
<artifactId>jdom</artifactId>
<groupId>jdom</groupId>
<version>1.0</version>
</dependency>
<dependency>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
...
</build>
2. The build.xml file in ${basedir}. The location for this is configured
in the POM plugin configuration above (antfile="${basedir}/build.xml").
<?xml version="1.0"?>
<project name="project-title" default="macker">
<description>
Ant task to run the Macker tool.
</description>
<target name="macker">
<taskdef name="macker"
classname="net.innig.macker.ant.MackerAntTask"
classpathref="maven.plugin.classpath"/>
<macker>
<!--
This classpath tells Macker where to look for its own
libraries, and the libraries used by the primary classes.
-->
<classpath refid="maven.plugin.classpath" />
<!--
Rules come from this file:
-->
<rules dir="src/test/macker" includes="macker.xml" />
<!--
Macker will apply those rules to these primary classes:
-->
<classes dir="target/classes">
<include name="**/*.class" />
</classes>
</macker>
</target>
</project>
3. The macker rules are placed in ${basedir}/src/test/macker/macker.xml.
This location is specified in build.xml above at
<rules dir="src/test/macker" includes="macker.xml" />
<?xml version="1.0"?>
<!DOCTYPE macker PUBLIC
"-//innig//DTD Macker 0.4//EN"
"http://innig.net/macker/dtd/macker-0.4.dtd">
<macker>
<ruleset name="Architectural rules for StoryType">
<!--
Define some rules here.
See http://innig.net/macker/guide/index.html
-->
</ruleset>
</macker>
Using 'mvn antrun:run' will run Macker on your compiled classes in
${basedir}/target/classes/
I hope I haven't forgot anything, and that this may be of interest for
others as well :)
Rune
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]