2014-03-31 40 views
1

你好我收到以下錯誤:無法創建任務或類型的Cobertura儀器

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> 

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

你解決問題了嗎?你能否更新你的文章或取得正確的答案? –

回答

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

我發現,在官方的文檔的準則是一點點有點誤導。 cobertura文件夾中的jar文件包含文件名中的版本號,因此您不能複製&粘貼該元素。

試試這個:

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