Reputation: 923
We are using Sonar for code analysis, which in turn uses findbugs i believe for the bytecode scan. The sonar execution is built within the ANT build system and is running on RHEL build host.
All of a sudden recently, the code coverage analysis started failing with the Noclasses found to analyse exception, which is puzzling when there are 7951 classes compiled in the binaries dir.
Here are the steps followed to collect the metrics *) Compile the code first *) Sonar target depends on unittest and triggers unittest *) Then executes the sonar section when the target is called
<target name="sonar" depends="run-testng-unittest-coverage">
<path id="sonar.classpath">
<fileset dir="${env.projecthome}/.m2/repository/" includes="**/*.jar"/>
<fileset dir="${env.3rdpartyhome}/" includes="**/*.jar"/>
</path>
<property name="sonar.projectKey" value="project-short-name"/>
<property name="sonar.projectVersion" value="1.0.0-SNAPSHOT"/>
<property name="sonar.projectName" value="PROJECT SHORT DESC"/>
<property name="sonar.language" value="java" />
<property name="sonar.branch" value="main"/>
<property name="sonar.host.url" value="http://sonar.instance:9000"/>
<property name="sonar.jdbc.url" value="jdbc:mysql://sonar.instance:3306/sonar?useUnicode=true&characterEncoding=utf8"/>
<property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="sonar.jdbc.username" value="sonar"/>
<property name="sonar.jdbc.password" value="sonar"/>
<property name="sonar.findbugs.timeout" value="3600000"/>
<property name="sonar.dynamicAnalysis" value="true"/>
<property name="sonar.java.coveragePlugin" value="cobertura"/>
<property name="sonar.core.codeCoveragePlugin" value="cobertura" />
<property name="sonar.sources" value="src"/>
<property name="sonar.tests" value="test/unit"/>
<property name="sonar.binaries" value="build/test/unit/classes,App/classes"/>
<pathconvert property="sonar.libraries" pathsep="," refid="sonar.classpath"/>
<property name="sonar.exclusions" value="orm/**/*,selenium/**/*,sql/**/*,test/**/*,xml/**/*,xsl/**/*"/>
<property name="sonar.sourceEncoding" value="ISO-8859-1"/>
<property name="sonar.skipPackageDesign" value="true"/>
<property name="sonar.surefire.reportsPath" value="${full.path.reports.testng}/unittest/junitreports"/>
<property name="sonar.cobertura.reportPath" value="${full.path.reports.testng}/unittest/cobertura/coverage.xml"/>
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="sonar.classpath" />
<sonar:sonar key="${sonar.projectKey}" version="${sonar.projectVersion}" xmlns:sonar="antlib:org.sonar.ant"/>
</target>
Error stack trace:
Caused by: java.util.concurrent.ExecutionException: edu.umd.cs.findbugs.NoClassesFoundToAnalyzeException: No classes found to analyze in /opt/project/build/test/unit/classes /opt/project/App/classes
at edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:274)
at org.sonar.plugins.findbugs.FindbugsExecutor$FindbugsTask.call(FindbugsExecutor.java:179)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Total time: 6 minutes 25 seconds
Count of total classes in the sonar binaries dir
find /opt/project/build/test/unit/classes /opt/project/App/classes -name "*.class" |wc -l
7951
Following are the version of plugins that Sonar downloads
Sonar version: 3.5.1
09:29:21.845 INFO .s.b.b.BatchSettings - Load batch settings
09:29:21.987 INFO o.s.h.c.FileCache - User cache: /opt/home/user/.sonar/cache
09:29:21.994 INFO atchPluginRepository - Install plugins
09:29:22.002 INFO b.b.PluginDownloader - Download sonar-findbugs-plugin-1.2.jar
09:29:22.262 INFO b.b.PluginDownloader - Download sonar-issues-report-plugin-1.0.jar
09:29:29.820 INFO b.b.PluginDownloader - Download sonar-timeline-plugin-1.3.jar
09:29:29.878 INFO b.b.PluginDownloader - Download sonar-clirr-plugin-1.1.jar
09:29:29.884 INFO b.b.PluginDownloader - Download sonar-l10n-en-plugin-3.5.1.jar
09:29:29.890 INFO b.b.PluginDownloader - Download sonar-scm-activity-plugin-1.5.jar
09:29:29.964 INFO b.b.PluginDownloader - Download sonar-sonargraph-plugin-3.0.5.jar
09:29:30.006 INFO b.b.PluginDownloader - Download sonar-pdfreport-plugin-1.3.jar
09:29:30.012 INFO b.b.PluginDownloader - Download sonar-cpd-plugin-3.5.1.jar
09:29:30.018 INFO b.b.PluginDownloader - Download sonar-fb-contrib-plugin-1.1.jar
09:29:30.040 INFO b.b.PluginDownloader - Download sonar-pmd-plugin-1.2.jar
09:29:30.107 INFO b.b.PluginDownloader - Download sonar-squid-java-plugin-1.2.jar
09:29:30.144 INFO b.b.PluginDownloader - Download sonar-technicaldebt-plugin-1.2.1.jar
09:29:30.150 INFO b.b.PluginDownloader - Download sonar-email-notifications-plugin-3.5.1.jar
09:29:30.179 INFO b.b.PluginDownloader - Download sonar-useless-code-tracker-plugin-0.5.jar
09:29:30.330 INFO b.b.PluginDownloader - Download sonar-motion-chart-plugin-1.4.jar
09:29:30.441 INFO b.b.PluginDownloader - Download sonar-quality-index-plugin-1.1.3.jar
09:29:30.447 INFO b.b.PluginDownloader - Download sonar-jacoco-plugin-1.2.jar
09:29:30.472 INFO b.b.PluginDownloader - Download sonar-jira-plugin-1.0.jar
09:29:30.547 INFO b.b.PluginDownloader - Download sonar-surefire-plugin-1.2.jar
09:29:30.554 INFO b.b.PluginDownloader - Download sonar-ldap-plugin-1.2.1.jar
09:29:30.565 INFO b.b.PluginDownloader - Download sonar-checkstyle-plugin-1.2.jar
09:29:39.093 INFO b.b.PluginDownloader - Download sonar-java-plugin-1.2.jar
09:29:39.100 INFO b.b.PluginDownloader - Download sonar-core-plugin-3.5.1.jar
09:29:39.113 INFO b.b.PluginDownloader - Download sonar-dbcleaner-plugin-3.5.1.jar
09:29:39.118 INFO b.b.PluginDownloader - Download sonar-cobertura-plugin-1.2.jar
09:29:39.123 INFO b.b.PluginDownloader - Download sonar-design-plugin-3.5.1.jar
09:29:39.989 INFO .s.b.b.TaskContainer - ------------- Executing Project Scan
09:29:40.635 INFO b.b.JdbcDriverHolder - Install JDBC driver
09:29:40.638 INFO b.b.JdbcDriverHolder - Download mysql-connector-java-5.1.18.jar
09:29:40.663 INFO .b.ProjectExclusions - Apply project exclusions
Can someone shed some light on this please..
Upvotes: 5
Views: 6175
Reputation: 1786
Just in case someone like me will end up on this question with "NoClassesFoundToAnalyze Exception" in Java 9+ era:
Firebugs is no longer supported and therefore it doesn't work with Java 9+ - use Spotbugs instead.
Upvotes: 9
Reputation: 11
Findbugs is used to check rules over compiled class, so you need to specify the target folder where ".class" files are allocated.
You should review the target directorry at findbug execution time.
Upvotes: 1