I found an interesting problem while integrating cobertura with maven to generate the test coverage report for my new code.
I have done following modificaitons in pom.xml file:
a) Added plug-in for cobertura
When I ran mvn cobertura:cobertura, I got the following error:
[INFO] Nothing to compile – all classes are up to date [INFO] [cobertura:instrument] [ERROR] java.lang.UnsupportedClassVersionError: net/sourceforge/cobertura/instru ment/Main (Unsupported major.minor version 49.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source)
By looking at this I came to a conclusion that this incompatible class version issue.
When i ran mvn –version command, it gave me following info. Evrything looks fine as expected.
Maven version: 2.0.9
Java version: 1.5.0_15 OS name: “windows xp” version: “5.1” arch: “x86” Family: “windows”
I should not see above exception as I am using right version of JDK (1.5.0_15). I checked JAVA_HOME and even JRE_HOME env variable and they pointed to right location.
When I executed java –version command, I see following results
java version “1.4.2_11” Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06) Java HotSpot(TM) Client VM (build 1.4.2_11-b06, mixed mode)
I still didn’t believe that’s the root cause of problem. I gave it a
try by uninstalling JRE 1.4.2 and installed JRE 1.5 and everything started working fine.
I believe(though I am not a maven guru) that MAVEN is not making use of environment variable (here JAVA_HOME) to execute the plug in. I have spent almost 3 hours of my time and i thought this might be helpful for people like me.