无法创建任务或键入cobertura-instrument

时间:2014-03-31 15:18:49

标签: ant cobertura ecobertura

嗨,我收到了以下错误:

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 包含以下目标:

<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.

2 个答案:

答案 0 :(得分:2)

我发现官方文档中的指南有点误导。 cobertura文件夹中的jar文件包含文件名中的版本号,因此您无法复制和粘贴元素。

请改为尝试:

<path id="cobertura.classpath">
    <fileset dir="${cobertura.dir}">
        <include name="cobertura*.jar" />
        <include name="lib/**/*.jar" />
    </fileset>
</path>

答案 1 :(得分:0)

您是否使用taskdef来定义corbertura-instrument任务?

Ant允许您创建可在Ant中使用的新的令人兴奋的任务,但您需要告诉Ant如何定义这些任务以及如何执行它们。幸运的是,Corbertura告诉你如何定义他们的taskdef

我建议在您的项目中将所需的Corbertura罐子放在${basedir}/antlib/corbertura下。这样,当有人检查项目时,他们会自动获得所需的Corbertura罐子,并且不必在他们的特定系统上安装它们:

<taskdef resource="tasks.properties">
    <path>
        <fileset dir="${basedir}/antlib/corbertura"/>
        <fileset dir="${lib.dir}/>"
    </path>
</taskdef>