The Issue

Running tests with Mule sometimes throws a ClassNotFoundException when it tries to lookup org.apache.commons.cli.ParseException. The following is the whole stack trace. If you’re encountering this, then this blog post is for you!

The problem stems from the commons-cli-1.2 JAR file that’s installed by Studio when running the populate_m2_repo script. The aim of this script is to install several Mule JARs in your local Maven repository so that you do not need to download them during one of your build processes. This is what is shown in the logs when running the populate_m2_repo script from inside Studio:

However, a few lines down, we get the following:

As you can see, the groovy-all JAR is overwriting the commons-cli JAR, resulting in a ClassNotFoundException.

The Fix

As a current workaround, remove the commons-cli-1.2 JAR file from your repository and run the Maven build process again. Maven will then download the correct commons-cli JAR from the central repository and your build should carry on without any problems. To verify whether you have the correct file, the real commons-cli JAR is only a few kilobytes in size. The incorrect commons-cli JAR (which really is groovy-all-1.8.6) is around 6.2 MB.

Why does this happen?

Opening up groovy-all-1.8.6.jar and searching for files called “pom.xml” results in only one file – that of commons-cli. The populate_m2_repo script is picking up this pom.xml file and subsequently overwrites the Apache Commons CLI JAR. It seems the Groovy guys are not packaging their own pom.xml with the groovy-all JAR, even though the real pom.xml can be found in the Central Maven Repository . This issue seems to remain in the latest nightly build of Groovy…

Hope this clears up any confusion you may have!

This post first published; 29th July 2014 on blog.ricston.com