Java & JS Files scan together on Sonarcloud

Hi, we have a repository which contains Java, Js, Json & Yml files in same folders. Some of the folders have mixed type files. The main language is Java and we are using gradle so I was running sonar-scanner using gradle. It does scans all the Java files but it does not scan any other file.

For example (this is just 1 folder structure of the project)

├── file1.js
├── file2.js
├── build.gradle
├── docs.json
├── package-lock.json
├── package.json
├── serverless.yml
└── src
├── main
│ ├── java
│ │ └── serverless
│ │ ├──
│ │ ├──
│ │
│ └── resources
│ ├── Schema.json
│ ├── Schema2.json

└── test
├── java
│ └── serverless
│ └──
└── resources
└── functiondata.json

I found out that I need to define the folders in sonar.sources property in build.gradle file but that threw an error that Java files can not be indexed twice. I tried then specifying file js file path individually which worked but I have a lot of js files and I can not enter all of their paths manually. I also can not use wildcards in gradle properties.

My question is that is there any better way I can scan all Java, Js and other files in our project using sonar-scanner?


Thanks for the project structure outline!

Hmm… sounds like your definition was somehow additive. Given your structure, I would try a full override on the analysis commandline: -Dsonar.sources=.


I did tried that but it throws me this error:

File can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

For some reason, if I add any folder which has java files in sonar.sources it always throws the same error.


Would you like to provide your full configuration list and/or your analysis log? You can find the full configuration list on the Background Tasks page, under the cog menu. Obviously, you’ll want to redact sensitive values.


For some reason I don’t have any failed attempts in the Background Tasks page you mentioned even though I just made a failed attempt but they are not being uploaded to sonarcloud.

Here is the error I have right now (this comes when I add sonar.sources=. to config)

This is what my current config looks like:



Always feel free to redact sensitive values.

So here’s what I see as the interesting part:

Scanner properties of module: module1
  - sonar.sources=/home/user/sub-folder/sub-folder-2/project-folder/api/src/main/java
  - sonar.tests=/home/user/sub-folder/sub-folder-2/project-folder/api/src/test/java
Scanner properties of module: module2
  - sonar.sources=/home/user/sub-folder/sub-folder-2/project-folder/folder/src/main/java

It looks like you’ll need to define - at the module1 level:


That should include the JS files at the top level of your module, and avoid the double-index error.


Even if I change the sonar.sources at the module 1 level it still throws the same error. These are the updates I made. I tried writing full absolute path and relative path and both returned the same error.


Just to clarify these are the addresses for module 1 & module 2 and then gradle file is in the same project folder:

Module 1: project-folder/api
Module 2: project-folder/module2 (calling it module 2 to make it easier)
Gradle build file: project-folder/build.gradle

What I don’t understand is that if I define sonar.sources at module 1 level then wouldn’t it completely skip scanning module 2 folder?

The only thing which works is if I define path to all the js files in sonar.sources one by one.


No, it would fall back to the default value of sonar.sources for module2.

To be clear, the error is can't be indexed twice?

Could you provide your analysis log, redacted as necessary?