codacy / codacy-coverage-reporter

Multi-language coverage reporter for Codacy
https://www.codacy.com
Other
135 stars 94 forks source link

NoClassDefFoundError thrown when running CodacyCoverageReporter #50

Closed fabiocarvalho777 closed 7 years ago

fabiocarvalho777 commented 7 years ago

Hello,

Whenever I run CodacyCoverageReporter I get the following error:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: scala.Product
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more

It happens when I run it manually from my laptop or also during automated builds in CI job, as you can see here (search for java.lang.NoClassDefFoundError: scala/Product).

The odd thing about it is that, regardless of this issue, apparently the coverage info seems to be uploaded.

rtfpessoa commented 7 years ago

Did you download the jar directly from maven?

rtfpessoa commented 7 years ago

If you follow the steps here: https://github.com/codacy/codacy-coverage-reporter#setup it should not happen

fabiocarvalho777 commented 7 years ago

I did download the jar directly from maven, and I did followed the instructions you pointed out. The only difference is that I used codacy-coverage-reporter-1.0.13.jar.

Your doc refer to codacy-coverage-reporter-assembly-1.0.5.jar though. So, when I use it, I get a different error, as seen below.

Error: Could not find or load main class com.codacy.CodacyCoverageReporter

rtfpessoa commented 7 years ago

If I do

wget https://github.com/codacy/codacy-coverage-reporter/releases/download/1.0.13/codacy-coverage-reporter-assembly-1.0.5.jar
java -cp codacy-coverage-reporter-assembly-1.0.5.jar com.codacy.CodacyCoverageReporter -l Java -r jacoco.xml

in a clean machine if requests my token so it is finding the class. Not sure what can be the problem. Do you have any aditional details? What are you exactly doing?

fabiocarvalho777 commented 7 years ago

The previous error I got when using a different jar codacy-coverage-reporter-1.0.13.jar. When I use codacy-coverage-reporter-assembly-1.0.5.jar though, I get [error] com.codacy Failed to upload report: Not Found. See all my commands below.

[facarvalho@LM-aun-00874876 resteasy-spring-boot]$ ls resteasy-spring-boot-starter/target/site/cobertura/coverage.xml 
resteasy-spring-boot-starter/target/site/cobertura/coverage.xml
[facarvalho@LM-aun-00874876 resteasy-spring-boot]$ java -cp codacy-coverage-reporter-assembly-1.0.5.jar com.codacy.CodacyCoverageReporter -l Java -r ./resteasy-spring-boot-starter/target/site/cobertura/coverage.xml  --projectToken XXXXXXXXXX
2017-04-19 11:43:54,297 [info]  com.codacy Parsing coverage data... 
2017-04-19 11:43:54,573 [info]  com.codacy Uploading coverage data... 
2017-04-19 11:43:55,815 [error] com.codacy Failed to upload report: Not Found
rtfpessoa commented 7 years ago

Weird. I just noticed the jar in the 1.0.13 release is 1.0.5 and that might be the actual problem. Can you try with https://secure.central.sonatype.com/maven2/com/codacy/codacy-coverage-reporter/1.0.13/codacy-coverage-reporter-1.0.13-assembly.jar ?

fabiocarvalho777 commented 7 years ago

I didn't work neither. I got: [error] com.codacy Failed to upload report: Not Found

My full command and output below:

[facarvalho@LM-aun-00874876 resteasy-spring-boot]$ ls -l ./resteasy-spring-boot-starter/target/site/cobertura/coverage.xml
-rw-r--r--  1 facarvalho  110111498  45591 Apr 17 10:45 ./resteasy-spring-boot-starter/target/site/cobertura/coverage.xml
[facarvalho@LM-aun-00874876 resteasy-spring-boot]$ java -cp codacy-coverage-reporter-1.0.13-assembly.jar com.codacy.CodacyCoverageReporter -l Java -r ./resteasy-spring-boot-starter/target/site/cobertura/coverage.xml  --projectToken XXXXXXXX
2017-04-20 11:18:28,353 [info]  com.codacy Parsing coverage data... 
2017-04-20 11:18:28,680 [info]  com.codacy Uploading coverage data... 
2017-04-20 11:18:30,024 [error] com.codacy Failed to upload report: Not Found 
rtfpessoa commented 7 years ago

I just updated one of our projects to use this instead of JPM.

https://github.com/codacy/codacy-api-java/blob/master/circle.yml#L7

Are you exporting the CODACY_PROJECT_TOKEN in the environment?

fabiocarvalho777 commented 7 years ago

Yes, I am CODACY_PROJECT_TOKEN in the environment. Keep in mind that before JPM broken codacy worked perfectly for me.

fabiocarvalho777 commented 7 years ago

I got the same com.codacy Failed to upload report: Not Found error after doing what you said. I am starting to wonder if my token is bad. What does that error message mean exactly? Does it mean the token is bad? Also, what is the token for? I am asking because even though I get that error message, I can tell still my coverage data gets uploaded.

rtfpessoa commented 7 years ago

Usually either the token is bad or the endpoint is wrong.

Old versions will have outdated endpoints since we changed some time ago.

Just to confirm, you are using the token generated in the project settings > integration > project token?

fabiocarvalho777 commented 7 years ago

The issue is finally solved. So, actually there were two issues here:

  1. The first was how to get the correct jar and run it properly, that was causing first java.lang.NoClassDefFoundError: scala/Product and later Error: Could not find or load main class com.codacy.CodacyCoverageReporter, depending on the jar used.
  2. There was in fact a problem with the token I had in the environment variable at my CI environment. That was causing com.codacy Failed to upload report: Not Found. That started to happen only after issue 1 was solved, but before we talked about how the token is used, we hadn't realized that.

I changed the way to get the codacy report tool (as seen here) and reset the codacy token in the CI environment and now everything works.

Thanks a lot Rodrigo for your time and getting this solved.

Feel free to close this issue.