嗨,我收到以下错误:
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.
构建.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>
构建属性
# 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.
我发现官方文档中的指南有点误导。cobertura 文件夹中的 jar 文件在文件名中包含版本号,因此您无法复制和粘贴该元素。
试试这个:
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura*.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
您是否使用 taskdef 来定义corbertura-instrument
任务?
允许您创建可在 Ant 中使用的令人兴奋的新任务,但您需要告诉 Ant 这些任务是如何定义的以及如何执行它们。幸运的是,Corbertura准确地告诉你如何定义他们的taskdef。
我建议将所需的Corbertura罐子放在项目中的${basedir}/antlib/corbertura
下。这样,当有人签出项目时,他们会自动获得所需的Corbertura jars,而不必将它们安装在他们的特定系统上:
<taskdef resource="tasks.properties">
<path>
<fileset dir="${basedir}/antlib/corbertura"/>
<fileset dir="${lib.dir}/>"
</path>
</taskdef>