13
votes

I am trying to get SonarQube findbugs working, but when I try to run it I get the error: "Findbugs needs sources to be compiled. Please build project before executing sonar and check the location of compiled classes."

sonar.sources is set to a folder with all of my src files and sonar.binaries is set to a folder with all of my class and jar files. This layout works with findbugs for one of my projects, but on the other I get the above error.

This is the debug error provided when FindBugs will not run: http://pastie.org/9483921

How can I fix this, and is there a certain folder FindBugs needs classes/jars in to work?

Thanks.

5
Have you compiled your stuff with debug information turned on (-g option of javac) in both cases? Debug information is required, and if missing can cause this error.barfuin
This is the debug error provided when FindBugs will not run: pastie.org/9483921 | There are no errors when FindBugs works on the second project.Kory
Yes, but have you checked the debug compiler setting? If you are building with Ant, then debug is turned off by default.barfuin
Can you point me to where this setting is? Most of this is new to me, so I apologize if I'm a little slow.Kory
Where the setting is depends on how you compile your sources. Which IDE are you using? Are you running SonarQube from within the IDE, or via a build tool like Ant, Maven, or Gradle?barfuin

5 Answers

9
votes

Add property

sonar.binaries=${workspace}/proy/build/

To Sonar Configuration. If you ar using several proyects to build, use coma separed.

3
votes

SonarQube requires source code to be built before it analyzes it. This is going to differ depending on how you are building it, but check here and click on your building platform.

For example: If you were using SonarQube to analyze a project with Maven, you must issue the following commands in this order (assuming you followed the steps according to this maven configuration page, which is linked as an option in the first link):

mvn clean install
mvn sonar:sonar

Thus, you must build the code before any sonar analysis can be done. Also note, you must issue these commands separately and you should wait for the install to finish completely before running sonar.

1
votes

I've faced the same issue in the past.

Check that you don't have a folder somewhere under the src/main folder containing only a pkg-info.java file. These files are javadoc files and are thus not compiled. However, the folder is created in target/classes, findbugs detects it but finds no .class which causes a crash with the “needs sources to be compiled” message.

The solution is to remove the folder with the pkg-info.java file or add real java sources files in it (which will be compiled and make findubgs happy.)

1
votes

If you do not want to compile and use sonar-runner as before , you can create a folder and put a valid java class there and execute as below:

sonar-runner -Dsonar.java.binaries=folder path
0
votes

sonar property names have changed, see http://docs.sonarqube.org/display/PLUG/Java+Plugin+and+Bytecode

e.g. sonar.java.binaries replaces sonar.binaries for plugin version > 2.5

This fixed my findbugs issue.