spotbugs / sonar-findbugs

SpotBugs plugin for SonarQube
358 stars 138 forks source link

Findbugs needs sources to be compiled. Please build project before executing sonar or check the location of compiled classes to make it possible for Findbugs to analyse your project. #49

Closed kamal2222ahmed closed 7 years ago

kamal2222ahmed commented 8 years ago

Here is the environment: Java - "1.8.0_102" OS: Redhat 6 findbugs - classpath 'com.google.code.findbugs:jsr305:3.0.1' gradle - 2.2.1 SonarScanner - 1.2 SonarQube - 5.6.1

doing a grep on findbugs from top level of repo results in the following

$(sonarscanner-k)$ ack findbugs .

build.gradle

6://apply plugin: 'findbugs'
103:      //classpath 'com.google.code.findbugs:jsr305:3.0.1'

Build/codeCoverage/test.gradle

3:apply plugin: 'findbugs'
67:task getfindbugsConfig(dependsOn: 'makeConfigDir') << {
71:getfindbugsConfig.mustRunAfter clean
72:getfindbugsConfig.outputs.file findBugsConfig
99:findbugs {
107:  findbugsMain {
115:findbugsMain.dependsOn getfindbugsConfig
116:build.mustRunAfter getfindbugsConfig
128:task codeAnalysis (dependsOn: ['findbugsMain','checkstyleMain','pmdMain'] )
h3xstream commented 8 years ago

I'm not familiar with sonar-scanner. I think it is unable to find the build directory. From what I can see in the documentation, it seems like manual configuration are required by sonar-scanner.

I would try specifying the following variable:

sonar.java.binaries=[YOUR_BUILD_DIR] (target/classes)
h3xstream commented 8 years ago

Let me know if the addition of the property does fix your problem.

I notice that this approach did work for somebody else: http://stackoverflow.com/questions/39102924/can-not-execute-findbugs-caused-by-this-project-contains-java-source-files-that

kstevenard commented 8 years ago

I have the same issue, what is really weird is that previously it was acting like if there was no rules comming from the findbugs repository then findbugs wasn't executed (could somebody confirm?) Now for a project i can't get the compiled code, what to do to have the analysis not failing? upgrade to 3.4.3 was required for us due to migration to SQ 5.6.1

StanleyShen commented 8 years ago

I have same issue right now.

I tried to compile the code, and tried to add

sonar.java.binaries=test/**/target/classes

But it seems it doesn't work. The project is maven one with multiple modules defined.

mgreau commented 8 years ago

I had the same issue with SonarQube 5.6.1 LTS and sonar-findbugs-plugin-3.4.3.jar. I fixed it by using the latest sonar-findbugs-plugin-3.4.4.jar (I installed it manually because this version is not yet available in the Update center)

steve-todorov commented 8 years ago

I'm having the same problem on SonarQube 6.1 with the latest sonar-findbugs-plugin3.4.4.jar and Sonar-Scanner 2.8. This is the exception I'm receiving in Jenkins:

WARN: Findbugs needs sources to be compiled. Please build project before executing sonar or check the location of compiled classes to make it possible for Findbugs to analyse your project.
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 19.522s
INFO: Final Memory: 65M/1105M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Can not execute Findbugs
    at org.sonar.plugins.findbugs.FindbugsExecutor.execute(FindbugsExecutor.java:169)
    at org.sonar.plugins.findbugs.FindbugsSensor.execute(FindbugsSensor.java:88)
    at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
    at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:57)
    at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:49)
    at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:182)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:247)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:242)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:232)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
    at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:115)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:118)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
    at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
    at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: This project contains Java source files that are not compiled.
    at org.sonar.plugins.findbugs.FindbugsConfiguration.getFindbugsProject(FindbugsConfiguration.java:120)
    at org.sonar.plugins.findbugs.FindbugsExecutor.execute(FindbugsExecutor.java:119)
    ... 31 more

@h3xstream Any ideas what might be causing this?

steve-todorov commented 8 years ago

I've managed to find the problem. The -Dsonar.sources was being incorrectly set to /java/jenkins/job/my-job/workspace. After changing it to /java/jenkins/job/my-job/workspace/.sonar everything started working.

peterfortuin commented 7 years ago

For me it helped to upgrade the sonarqube plugin in gradle to 2.2.1.

plugins {
    id "org.sonarqube" version "2.2.1"
}
tydaeus commented 7 years ago

FYI, the sonar.java.binaries assignment only works for me when pointing at the dir containing the intermediary .class files, not at the dir with the final output jar file.

nfalco79 commented 7 years ago

This bug also hit me. Actual system SonarQube 5.6.6

Recent updates of sonarqube plugins cause a build failure in our Jenkins CI system. We run sonar as part of maven build using sonar maven plugin with sonar:sonar goal, so I suppose all properties are setup in the correct way. There is a maven module with just web.xml and a couple of JSPs files (like login.jsp). These jsp are not pre-compiled (and we don't want). Before the plugin update all works.

[INFO] ------------- Scan acme.model.admin.ui.web master [INFO] Excluded sources for coverage: [INFO] test/ [INFO] /*NLS.java [INFO] /*DTO.java [INFO] */Dto.java [INFO] /*Bean.java [INFO] /*Constants.java [INFO] */Consts.java [INFO] Base dir: /var/lib/jenkins/workspace/acme_master-AZ5ORYFOO25DAUG767DB32IPS36JL64GOEK6QCFL6266VKWQXSCQ/bundles/acme.model.admin.ui.web [INFO] Working dir: /var/lib/jenkins/workspace/acme_master-AZ5ORYFOO25DAUG767DB32IPS36JL64GOEK6QCFL6266VKWQXSCQ/bundles/acme.model.admin.ui.web/target/sonar [INFO] Source paths: pom.xml, src [INFO] Binary dirs: target/classes [INFO] Source encoding: UTF-8, default locale: en_US [INFO] Index files [INFO] Excluded sources: [INFO] /*NLS.java [INFO] /*DTO.java [INFO] */Dto.java [INFO] /*Bean.java [INFO] /*Constants.java [INFO] */Consts.java [INFO] file:/src-gen/ [INFO] file:/test-gen/** [INFO] 3 files indexed [INFO] 0 files ignored because of inclusion/exclusion patterns [INFO] Quality profile for jsp: FindBugs Security JSP [INFO] Sensor Lines Sensor [INFO] Sensor Lines Sensor (done) | time=1ms [INFO] Sensor SCM Sensor [INFO] Sensor SCM Sensor (done) | time=1ms [INFO] Sensor jsp [INFO] Sensor jsp (done) | time=106ms [INFO] Sensor FindBugs Sensor [INFO] JavaClasspath initialization [INFO] JavaClasspath initialization (done) | time=4ms [WARNING] Findbugs needs sources to be compiled. Please build project before executing sonar or check the location of compiled classes to make it possible for Findbugs to analyse your (sub)project (/var/lib/jenkins/workspace/acme_master-AZ5ORYFOO25DAUG767DB32IPS36JL64GOEK6QCFL6266VKWQXSCQ/bundles/acme.model.admin.ui.web).

Do you have suggestion to fix the issue?

h3xstream commented 7 years ago

This will be fixed by #148

Temporarily you can run :

  1. Run mvn findbugs:findbugs
  2. Run mvn sonar:sonar [...]

Make sure that plugins use in Sonar-FindBugs is also configured in your Maven configuration.

Long-term plan

A new configuration to disable compiled code check will be added in 1 or 2 release.

pgodithi commented 6 years ago

Hey I am using oracle java 10 and using sonar for code analysis, getting the following error, can anyone tell me the solution for this. sonarqube version: 6.7.3 find bugs plugin: 3.7.0

at edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:275) at org.sonar.plugins.findbugs.FindbugsExecutor$FindbugsTask.call(FindbugsExecutor.java:235)

Caused by: java.lang.IllegalStateException: Can not execute Findbugs

haribalaji89 commented 5 years ago

I am using oracle java 8, Sonarqube server : 6.7 and Apache Ant(TM) version 1.10.5 ran into same error as above in Findbugs.

Caused by: java.lang.IllegalStateException: Can not execute Findbugs Caused by: java.nio.file.InvalidPathException: Illegal char <*> at index 0: /lib/ at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94) at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255) at sun.nio.fs.AbstractPath.resolve(AbstractPath.java:53) at org.sonar.api.scan.filesystem.PathResolver.relativeFile(PathResolver.java:44) at org.sonar.plugins.findbugs.FindbugsConfiguration.getExcludesFilters(FindbugsConfiguration.java:214) at org.sonar.plugins.findbugs.FindbugsExecutor.execute(FindbugsExecutor.java:152)

appreciate any help related to this