我们正在使用 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"
我对两个主要项目进行了 grep:
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",