Analysis JavaScript and Java in one project

Hi, sonarcloud , I create a Github action to analysis a project with both Java and JavaScript using maven command .Both Java and JavaScript were building successful. JavaScript source file was build by plugin in pom.xml file . As a result ,Java source files were analyzed correctly, but none of JavaScript were not.

Project url:

JavaScript source files are udner dolphinscheduler-ui/src folder .

Sonarcloud url:
https://sonarcloud.io/dashboard?id=apache-dolphinscheduler

You can see that at sonarcloud https://sonarcloud.io/code?id=apache-dolphinscheduler&selected=apache-dolphinscheduler%3Adolphinscheduler-ui the dolphinscheduler-ui folder is just one pom.xml file .

It seems that because I use maven command , sonarcloud treat the project as Java project and ignore JavaScript .

So,is there a way to analysis one project using both Java and JavaScript ?

I searched some result ,

said

Nothing has changed so far on the fact that one project must match one repo only.

And I tried this

using sonar.inclusions ,but get “file already indexed” error .

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
    GitHub

  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI
    GitHub action

  • Scanner command used when applicable (private details masked)

name: SonarCloud
on: [push, pull_request]
jobs:
  sonarCloudTrigger:
    name: SonarCloud Trigger
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-java@v1
      with:
        java-version: 8
    - uses: actions/cache@v1
      with:
        path: ~/.m2/repository
        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-sonarqube
        restore-keys: |
          ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-sonarqube
          ${{ runner.os }}-maven-
    - name: Maven clean
      run: mvn clean
    - name: Run SonarCloud analyse
      run: >
          mvn clean --batch-mode
          org.jacoco:jacoco-maven-plugin:prepare-agent
          verify
          org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
          -Dmaven.test.skip=true
          -Dsonar.host.url=https://sonarcloud.io/
          -Dsonar.organization=apache
          -Dsonar.projectKey=apache-dolphinscheduler
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  • Languages of the repository
    Java and JavaScript

Hello @Jave-Chen, welcome to the community forum!

It is certainly to analyse both Java and Javascript code with the Maven scanner.
In your case adding

<properties>
    <sonar.sources>src/js</sonar.sources>
</properties>

to the dolphinscheduler-ui/pom.xml should make the the analyser detect your Javascript files as well.

Hope that helps,
Tom

Wow, Tom you really given me a big favor. It worked.Thank you very much.
Further more, Can you tell me why Maven scanner ignore JavaScript files when I didn’t add sonar.sources ?

BTW, sonar.host.url should be sonar.sources.

<properties>
<sonar.sources>src/js</sonar.sources>
</properties>

When launching a sonar analysis through maven, the Java sources automatically get added because of the Maven src/main/java convention. The same convention does not exist for other languages so their location has to be manually specified.

Thanks, I fixed that.