Using Flex PMD for Flex Code Review using ANT

Hi All,

Adobe Technical Services launched FlexPMD – a tool to audit  ActionScript source code and detect common problems (anti patterns, unused code, badly written Flex components ). The tool started as an internal project in Adobe and now it has been made open source.

I can say that using this tool is a must for any complex Flex projects, because it enables you to detect common problems at an early phase. For the moment it can be invoked from Maven/Ant and Mac OS X automaton, in the future it will probably also be available as a Flash Builder plugin.

Below I will detailed out how to use this with ANT script, to get a report.

Step 1: Download the required jars.

Step 2: Copy the jars in Lib folder e.g  c:\myproject\lib

Step 3: Write an ant script and add those jars into Classpath.

Flex PMD example
<mkdir dir=”${basedir}/flex/” />
<mkdir dir=”${basedir}/bin1/” />
<property name=”src.dir” value=”${basedir}/flex/” />
bin1/” />

<property name=”flexpmd.version” value=”1.1″ />
<property name=”flexpmd.dir” value=”jars/flex-pmd-ant-task-1.1/” />


<taskdef name=”flexPmd”
<pathelement location=”${flexpmd.dir}/flex-pmd-ruleset-api-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/flex-pmd-ruleset-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/flex-pmd-core-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/as3-plugin-utils-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/as3-parser-api-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/pmd-4.2.5.jar”/>
<pathelement location=”${flexpmd.dir}/commons-lang-2.4.jar”/>
<pathelement location=”${flexpmd.dir}/flex-pmd-files-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/plexus-utils-1.0.2.jar”/>

<target name=”flexPmdWithCustomRuleset”>


Step 4: Run the ant scripts  e.g  >ant flexPmdWithDefaultRuleset

Step 5: After running the ant task, you will see the task output details on the Console.

[flexPmd] 01-Jun-2010 20:34:09 loadRuleset
[flexPmd] INFO: Ruleset: c:\DOCUME~1\603\LOCALS~1\Temp\default_flex5303689465491432723.xml
[flexPmd] 01-Jun-2010 20:34:09 loadRuleset
[flexPmd] INFO: Rules number in the ruleSet: 90
[flexPmd] 01-Jun-2010 20:35:01 computeViolations
[flexPmd] INFO: It took 51497ms to compute violations
[flexPmd] 01-Jun-2010 20:35:01 computeViolationNumber
[flexPmd] INFO: Violations number found: 3256
[flexPmd] 01-Jun-2010 20:35:01 writeReport
[flexPmd] INFO: Creating report in
[flexPmd] 01-Jun-2010 20:35:01 writeAnyReport
[flexPmd] INFO: It took 390ms to write the Xml report

The main things is that it works well on MXML files. Covers all the action script code written.

Also we can easily transform it to some HTML Report by using XSL. Simply give the path of generated report and path of XSL and the location of HTML report.

<xslt in=”${bin.dir}/pmd.xml” style=”pmd-nicerhtml.xsl” out=”bin1/pmd.html” />
Tip: XSL can be found inside pmd-4.2.5.jar, etc folder

R Vashi

3 thoughts on “Using Flex PMD for Flex Code Review using ANT

  1. Rakesh

    Hi Vashi,

    Thanks for the article. Its very neatly written and covers all the basic needs to get a proper output. Thanks for your time and effort.

  2. Jay

    Thanks for the example. It helped me get started with Flex PMD.

    One note that you might want to look into is the quotes came out as the Microsoft Smart Quotes when I pasted it into my editor. It looks wordpress is doing that.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.