Analyze both Java and Javascript from the same repo and gradle pipeline

Info:

  • ALM used: Bitbucket Cloud
  • CI system used: Bitbucket Cloud pipelines
  • Using Gradle with java, sonarqube and jacoco plugins
  • build: ./gradlew build jacocoTestReport sonarqube
  • Languages of the repository: Java, Javascript, typescript

I have this currently working for Java, with a SonarCloud project showing results for branches from a Bitbucket repo. This is a gradle build using the sonar and jacoco plugins. I’m trying to add Javascript (and typescript) analysis in addition to Java but can’t figure out how to do that. I’m just trying to get static code analysis of the js and ts files, although I’d like to add the coverage for Javascript as well (we are using Jest).

Any pointers on how to do this?

Hi,

did you check the docs https://docs.sonarqube.org/latest/analysis/languages/javascript/ already ?

Yes, but that is for configuring a SonarQube scanner, not for using SonarCloud. SonarCloud already supports Javascript and has Bitbucket Cloud integration, I just need to understand what I need to do in the Bitbucket pipeline to get the Javascript scan invoked along with the Java scan I’m already doing and get the results sent to the SonarCloud project.

I have this working now. The sonar.sources and sonar.tests properties are defaulted to the sourceSets.main and sourceSets.tests values which are being set by the Java gradle plugin. I overrode both properties to list both java and javascript source directories and started getting the expected results. e.g.

sonarqube {
  properties {
    property 'sonar.sources', 'src/main/java,src/main/webapp'
    property 'sonar.tests', 'src/test/java,src/frontend/test'
  }
}
4 Likes

Thanks for posting the solution, will help others.

2 Likes