2

Hi I am getting the Below Error:

build.xml:61: Problem: failed to create task or type cobertura-instrument
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

Build .xml contains the below target :

<target name="instrument" depends="init,compile">
        <!--
            Remove the coverage data file and any old instrumentation.
        -->
        <delete file="cobertura.ser"/>
        <delete dir="${instrumented.dir}" />

        <!--
            Instrument the application classes, writing the
            instrumented classes into ${build.instrumented.dir}.
        -->
        <cobertura-instrument todir="${instrumented.dir}">
            <!--
                The following line causes instrument to ignore any
                source line containing a reference to log4j, for the
                purposes of coverage reporting.
            -->
            <ignore regex="org.apache.log4j.*" />

            <fileset dir="${classes.dir}">
                <!--
                    Instrument all the application classes, but
                    don't instrument the test classes.
                -->
                <include name="**/*.class" />
                <exclude name="**/*Test.class" />
            </fileset>
        </cobertura-instrument>
    </target>

Build.properties

# The source code for the examples can be found in this directory
src.dir=C:/Rahul/SVN_CodeBase/services/src

# The path to cobertura.jar
cobertura.dir=C:/Rahul/SVN_CodeBase/cobertura-2.0.3

# Classes generated by the javac compiler are deposited in this directory
classes.dir=C:/Rahul/SVN_CodeBase/services/build/classes

# Instrumented classes are deposited into this directory
instrumented.dir=services/build/classesinstrumented

# All reports go into this directory
reports.dir=services/build/reports

# Unit test reports from JUnit are deposited into this directory
reports.xml.dir=${reports.dir}/junit-xml
reports.html.dir=${reports.dir}/junit-html

# Coverage reports are deposited into these directories
coverage.xml.dir=${reports.dir}/cobertura-xml
coverage.summaryxml.dir=${reports.dir}/cobertura-summary-xml
coverage.html.dir=${reports.dir}/cobertura-html


please let me know how to resolve the above error tanks in advance.
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
Rahul Jain
  • 115
  • 3
  • 12

2 Answers2

2

I found that the guidelines in the official docs are a little bit misleading. The jar file in the cobertura folder contains the version number in the file name, thus you cannot copy&paste the element.

Try this instead:

<path id="cobertura.classpath">
    <fileset dir="${cobertura.dir}">
        <include name="cobertura*.jar" />
        <include name="lib/**/*.jar" />
    </fileset>
</path>
Markus L
  • 932
  • 2
  • 20
  • 38
0

Did you use taskdef to define the corbertura-instrument task?

Ant allows you to create new and exciting tasks that can be used in Ant, but you need to tell Ant how these tasks are defined and how to execute them. Fortunately Corbertura tells you exactly how to defined their taskdef.

I recommend putting the required Corbertura jars under ${basedir}/antlib/corbertura in your project. This way, when someone checks out the project, they get the required Corbertura jars automatically, and don't have to install them on their particular system:

<taskdef resource="tasks.properties">
    <path>
        <fileset dir="${basedir}/antlib/corbertura"/>
        <fileset dir="${lib.dir}/>"
    </path>
</taskdef>
David W.
  • 105,218
  • 39
  • 216
  • 337