JavaScript not being analyzed

We’re using SonarQube Version 7.9.2, Scanner Version 4.3.0.2102, Sonarjs Version 6.2.2

We are trying to achieve the analysis of Javascript. The project utilizes Gradle.

So far we have:

  • Verified NodeJS version is above 8 (current version is node --version v12.18.4)

  • Insured there were no inclusions set so the whole project would scan.

  • Set inclusion to anaylze /ui/ where all js is located

Extra Information:

  • SonarQube analyzes Java.

hello @Kelby_Behounek,

can you share a bit structure of your project and how you configure sonarqube properties in your build? Can you include log of your analysis?

Hello,

These are the properties defined within the project itself.

sonarqube {
    properties {
        property "sonar.projectName", "ERM"
        property "sonar.projectKey", "drms"
    }
}

I have tried setting the property “sonar.sources” in that block as well. We are defining the analysis scope via the GUI on SonarQube.

sonarStage.txt (26.2 KB)

@saberduck posted the requested information any assistance would be appreciated.

I don’t see any mention of JavaScript plugin in the logs. Can you verify that it is really installed? Can you please enable debug level logs and post them here?

The plugin so SonarJS is indeed installed

I attempted the following, however see no real change in the log output:

sonarqube {
properties {
property “sonar.projectName”, “ERM”
property “sonar.projectKey”, “drms”
property “sonar.log.level”, “DEBUG”
}
}

I may be setting that property incorrectly

Sorry, I missed your reply.

Can you try to run gradle with -d to have debug logs?

hello @Kelby_Behounek,

these are the logs from the server, to investigate this issue we need logs from the analysis, i.e. where you execute gradle sonarqube task

1 Like

From the log I see this is multi-module gradle build. We need to configure sonar.sources property specifically for ui module. I recommend adding following to the build.gradle file in ui subdirectory

sonarqube {
    properties {
        property "sonar.sources", "."        
    }
}

More details on gradle multi-module project configuration is available here https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/

@saberduck
I tried that addition and get the following after a “Succesful” scan

image

There is no code at all. In the root build.gradle we have
sonarqube {
properties {
property “sonar.projectName”, “ERM”
property “sonar.projectKey”, “drms”
}
}

From the logs it seems that analysis is now running correctly, you can see that 190 JavaScript files are being analyzed in the ui module

2020-10-27T14:05:21.455+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] 190 source files to be analyzed

Did you wait until analysis was processed on the server side? You can check in the project background task if the analysis has finished processing.

1 Like

Yes the background task are/were complete via Background Tasks for the project

OK, it seems that there is some issue related to branch analysis. Just to avoid dealing with multiple problems at the same time, can you please run analysis with current settings on the main branch? Once we establish that analysis is running correctly on the main branch, we can troubleshoot short-live branch settings

Set in the property within the master branch and our code is now analyzed Thank you very MUCH. Can you explain to me why the property needs set in ui/build.gradle?

When set in build.gradle at root level of project the following error happens “Sonar fails with can’t be indexed twice Error. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files”

My reason for the questioning is just that it seems having to set it in the ui seems like a hack to me.

Thanks again!

1 Like

In multi-module projects each module is analyzed separately, because configuration is different (each module can have different dependencies, source directories, etc…), that’s why we need to configure sonar.sources property for that specific module.

I would be interested to understand what kind of build instructions you use for the ui module, I think we could improve our gradle plugin to pick up the configuration automatically, so it is not necessary to configure it (we already do that for Java modules). Do you use some plugin to build and package your JS sources?

Here are the build.gradle for at the root level and for in ui. Along with the method that we utilize as well for the sonar analysis stage in Jenkins.
gradleSonarAnalysisMethod.txt (638 Bytes) buildGradle.txt (1.1 KB) uiBuildGradle.txt (2.7 KB)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.