18

Is it just me or the cobertura-maven-plugin doesn't work with java 8? when it runs I get

[INFO] --- cobertura-maven-plugin:2.6:instrument (default) @ provider-impl ---
[INFO] Cobertura 2.0.3 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura] WARN  [main] net.sourceforge.cobertura.instrument.CoberturaInstrumenter - Unable to instrument file /var/lib/jenkins/workspace/BranchBuilder/implementations/provider-impl/target/generated-classes/cobertura/com/foo/impl/internal/ServiceProviderImpl$JoinRunner.class
java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:147)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:234)
at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:298)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:307)
at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:399)

I know there were issues with ASM and java 8 so I suspect the issue is that the maven-plugin has not been updated to use a java-8 compatible version of ASM

For reference, I asked the question here but got no answer

Has anyone managed to use cobertura-maven-plugin with java 8?

Hilikus
  • 9,954
  • 14
  • 65
  • 118

3 Answers3

18

I was able to get it working by manually updating the ASM dependency used by the cobetura-maven-plugin. Here is a link with more details: http://www.befreeman.com/2014/09/getting-cobertura-code-coverage-with.html

Brian F
  • 206
  • 1
  • 2
  • 2
    Actually, as you start using the more exotic features of Java 8 more often, this workaround seems to stop working, unfortunately. :( – metaforge Nov 17 '14 at 21:58
  • @metaforge Please see https://github.com/cobertura/cobertura/issues/166#issuecomment-64662005 for a possible solution. Brian F this answer might be incomplete, you need to update other dependencies, please see my github link – Hilikus Jan 19 '15 at 16:37
  • 6
    Did not work for me when I used lambdas - is there a way to work around that as well? – Neel Jun 14 '15 at 00:18
6

It is an open issue to make it understand new classformat ,
https://github.com/mojohaus/cobertura-maven-plugin/issues/21

Bax
  • 4,260
  • 5
  • 43
  • 65
jmj
  • 237,923
  • 42
  • 401
  • 438
  • ah, my query for "maven-cobertura-plugin java 8" didn't return that. I blame google ;) thank you – Hilikus Sep 02 '14 at 16:56
  • 12
    This issue has been fixed now and is available in version `2.7` – stalet Apr 08 '15 at 08:12
  • 1
    Codehaus JIRA no longer exists. A similar github issue with some open references (streams and lambdas): https://github.com/mojohaus/cobertura-maven-plugin/issues/21 – Bob Fields May 22 '17 at 14:51
3

This also happens if you have a cobertura plugin in your <build> and <reporting> sections. Remove one and the problem will go away.

louxiu
  • 2,830
  • 3
  • 28
  • 42
RonanOD
  • 876
  • 1
  • 9
  • 19