使用Cobertura会产生NoClassDefFoundError

时间:2012-12-23 20:05:01

标签: gradle cobertura

我们正在使用Cobertura(在gradle构建中定义)。当我部署应用程序并在swing客户端中单击时,会出现来自cobertura的NoClassDefFoundError。

java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/HasBeenInstrumented
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at com.sun.jnlp.JNLPClassLoader.findClass(JNLPClassLoader.java:345)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)

我不知道这是来自哪里。我的java代码中没有来自cobertura的内容。定义cobertura的唯一地方是在gradle构建文件中作为依赖项:

testCompile "net.sourceforge.cobertura:cobertura:1.9.4.1"

我对两个主要项目进行了深思熟虑:

find -type f -name "*gradle*" -exec grep -Hn cobertura {} \;

结果如下:

./BigTableDataProvider/ext-test/build.gradle:7:def cobSerFile = "$buildDir/cobertura.ser"
./BigTableDataProvider/ext-test/build.gradle:24:    testCompile 'net.sourceforge.cobertura:cobertura:1.9.4.1'
./BigTableDataProvider/ext-test/build.gradle:34:    codeCoverageRun 'net.sourceforge.cobertura:cobertura:1.9.4.1'
./BigTableDataProvider/ext-test/build.gradle:42:    jvmArgs = sampleJvmArg.split(" ").toList() << "-Dnet.sourceforge.cobertura.datafile=$cobSerFile"
./BigTableDataProvider/ext-test/build.gradle:50:        'cobertura-instrument'(datafile: cobSerFile) {
./BigTableDataProvider/ext-test/build.gradle:63:    ant.'cobertura-report'(destdir: "${project.buildDirName}/reports/codeCoverage",

./BigTableExplorer/sample/server/build.gradle:10:    testCompile 'net.sourceforge.cobertura:cobertura:1.9.4.1' // Add this if sample module has inherited classes from server.
./BigTableExplorer/ext-server/build.gradle:20:    testCompile "net.sourceforge.cobertura:cobertura:1.9.4.1"
./BigTableExplorer/ext-test/build.gradle:7:def cobSerFile = "cobertura.ser"
./BigTableExplorer/ext-test/build.gradle:22:    testCompile 'net.sourceforge.cobertura:cobertura:1.9.4.1'
./BigTableExplorer/ext-test/build.gradle:34:    codeCoverageRun 'net.sourceforge.cobertura:cobertura:1.9.4.1'
./BigTableExplorer/ext-test/build.gradle:42:    jvmArgs = sampleJvmArg.split(" ").toList() << "-Dnet.sourceforge.cobertura.datafile=$cobSerFile"
./BigTableExplorer/ext-test/build.gradle:50:        'cobertura-instrument'(datafile: cobSerFile) {
./BigTableExplorer/ext-test/build.gradle:63:    ant.'cobertura-report'(destdir: "${project.buildDirName}/reports/codeCoverage",

1 个答案:

答案 0 :(得分:1)

您无意中部署了Cobertura检测的代码。 Gradle构建必须使用某些第三方Cobertura插件或Cobertura Ant任务,显然配置不正确。