Jacoco Agent in ANT how to use

5,786 views
Skip to first unread message

Johannes Müller

unread,
Nov 2, 2012, 11:08:30 AM11/2/12
to jac...@googlegroups.com
Hello list,

i am wondering if i use the agent right with my ANT script.

0. place before the "tests" start

1. declare taskdef.

<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
      <classpath path="path_to/jacocoant.jar"/>
</taskdef>

2. declare agent
2.1 place in the target name="test"

<jacoco:agent property="agentvmparam" destfile="dir_to_dest/jacoco.exec" includes="*" output="file" dumponexit="true" />

3. declare VM  (thats the big question)


<property name="extraVMargs" value="${agentvmparam}"/>

4. generate report:
4.1. palace after the test

<jacoco:report>
                            <executiondata>
                                <file file="dir_to_dumped/jacoco.exec"/>
                            </executiondata>
                            <structure name="AS50">
                                <classfiles>
                                    <fileset dir="dir_to/plugins/">
                                    </fileset>
                                </classfiles>
                                <sourcefiles encoding="UTF-8">
                                    <fileset dir="dir_to_src/checkout_temp">
                                        <include name="*/plugins/*/src"/>
                                        <include name="*/*/plugins/*/src"/>
                                        <include name="*/*/*/plugins/*/src"/>
                                    </fileset>
                                </sourcefiles>
                            </structure>
                            <html destdir="dir_to_html}/jacoco"/>
</jacoco:report>


do i get this right?

Thanks and regards

Johannes

Marc Hoffmann

unread,
Nov 2, 2012, 11:38:17 AM11/2/12
to jac...@googlegroups.com
Hi,

JaCoCo Ant tasks are well documented:

http://www.eclemma.org/jacoco/trunk/doc/ant.html

I recommend starting with the working Ant example provided JaCoCo
download:

http://www.eclemma.org/jacoco/trunk/doc/examples/build/build.xml

Redaring your point 3. Ant documentation shows how to declare JVM
arguments:

http://ant.apache.org/manual/Tasks/java.html

Best regards,
-marc
> --

Johannes Müller

unread,
Nov 2, 2012, 12:33:43 PM11/2/12
to jac...@googlegroups.com
HI Marc,

thank you for your reply. Since i do not use java, junit, testng i can
not use the coverage task, or can i? I tought i use the agent and
there is no example how to use it. Where do i put the agent? Can i put
it everywhere in my ANT Script? Or does it need a special place to be?

I ask because i get this:

java.lang.IncompatibleClassChangeError: class
org.jacoco.core.internal.flow.ClassProbesVisitor has interface
org.objectweb.asm.ClassVisitor as super class

Can you interpret whats happening?

Thanks and regards

Johannes



2012/11/2 Marc Hoffmann <hoff...@mountainminds.com>
> --
>
>

Marc R. Hoffmann

unread,
Nov 2, 2012, 12:37:15 PM11/2/12
to jac...@googlegroups.com
Hi Johannes,

this means there is another ASM version which conflicts with JaCoCo
(which ship with ASM 4.0). At what step do you get this error? While
report generation?

Best regards,
-marc

Johannes Müller

unread,
Nov 5, 2012, 5:29:52 AM11/5/12
to jac...@googlegroups.com
HI Marc,

thank you for your answer. You are absolutely right:

[java] [echo] running uc tests

[java] cleanup:
[java] run:
[java] [jacoco:report] Loading execution data file
E:\builds\as50_middletier_junit_tests_vikaead_test2\report\middeltier\jacoco.exec
[java] BUILD FAILED
[java] java.lang.IncompatibleClassChangeError: class
org.jacoco.core.internal.flow.ClassProbesVisitor has interface
org.objectweb.asm.ClassVisitor as super class

how to solve this problem? I have tried many agend locations and
settings but nothing seems to work.

Thanks and regards,

Johannes



2012/11/2 Marc R. Hoffmann <hoff...@mountainminds.com>:
> --
>
>

Marc Hoffmann

unread,
Nov 5, 2012, 5:55:22 AM11/5/12
to jac...@googlegroups.com
Hm, what is the Ant version you're using? How are you executiong your
scripts?

From my understanding Ant should give every task definition a separate
class loader. Probably in your setup there is another ASM version due to
some global classpath definition or optional libraries.

Anyways I will open a issue to rename the ASM classes within our
all-in-one jacocoant.jar library to avoid such clashes in future.

Cheers,
-marc

Johannes Müller

unread,
Nov 5, 2012, 6:24:06 AM11/5/12
to jac...@googlegroups.com
My version is ant-1.8.1. I execute them from a Jenkins server. I
looked it up an i got in my scripts two taskdef declarations of the
"org/jacoco/ant/antlib.xml". In about two hours i can tell you if it
worked ;) this is the time a build needs to be executed and tested.

Thanks and regards

Johannes

2012/11/5 Marc Hoffmann <hoff...@mountainminds.com>:
> --
>
>

Johannes Müller

unread,
Nov 5, 2012, 8:43:14 AM11/5/12
to jac...@googlegroups.com
So the test is done:

[java] [echo] running uc tests
[java] [jacoco:report] Loading execution data file E:\builds\xxxx\jacoco.exec
[java] [java] BUILD FAILED
[java] java.lang.IncompatibleClassChangeError: class
org.jacoco.core.internal.flow.ClassProbesVisitor has interface
org.objectweb.asm.ClassVisitor as super class
[java] at java.lang.ClassLoader.defineClass1(Native Method)
[java] at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
[java] at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
[java] at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1146)
[java] at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1324)
[java] at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1388)
[java] at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1341)
[java] at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1088)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[java] at org.jacoco.ant.ReportTask.createBundle(ReportTask.java:472)
[java] at org.jacoco.ant.ReportTask.createReport(ReportTask.java:454)
[java] at org.jacoco.ant.ReportTask.execute(ReportTask.java:402)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[java] at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:597)
[java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[java] at org.apache.tools.ant.Task.perform(Task.java:348)
[java] at org.apache.tools.ant.Target.execute(Target.java:357)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[java] at org.eclipse.ant.internal.core.ant.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[java] at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:662)
[java] at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:534)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:597)
[java] at org.eclipse.ant.core.AntRunner.run(AntRunner.java:513)
[java] at org.eclipse.ant.core.AntRunner.start(AntRunner.java:600)
[java] at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
[java] at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
[java] at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
[java] at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
[java] at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:597)
[java] at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
[java] at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
[java] at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
[java] at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
[java] at org.eclipse.core.launcher.Main.main(Main.java:34)


Same error i guess are there some quick fixes for that or do i need to
wait for the update?

Thanks and regards,

Johannes

2012/11/5 Johannes Müller <johannes....@gmail.com>:

Johannes Müller

unread,
Nov 5, 2012, 10:01:43 AM11/5/12
to jac...@googlegroups.com
If it helps jacoco just created a jacoco.exec with one complete plugin
test in it...

2012/11/5 Johannes Müller <johannes....@gmail.com>:

Marc Hoffmann

unread,
Nov 5, 2012, 2:08:48 PM11/5/12
to jac...@googlegroups.com
The agent and coverage task has no dependency on ASM, that's why the
exec file can be created.

Here are some options I see for you:

1) Figure out why AMS 3.x is on the Ant classpath in your case. With
typical Ant setups JaCoCo 0.6.0 runs fine.
2) Go back to a JaCoCo 0.5.10 which is based on ASM 3.x
3) Wait until we have re-packaged jacocoant.jar

Best regards,
-marc

Johannes Müller

unread,
Nov 6, 2012, 7:37:26 AM11/6/12
to jac...@googlegroups.com
HI Marc,

point 2. worked just fine thanks!

regards Johannes

2012/11/5 Marc Hoffmann <hoff...@mountainminds.com>:
> --
>
>
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages