I have a requirement to support both “java” and “kotlin” in sonar qube through gradle.
But ‘sonar.language’ property takes only single language and is deprecated from 4.2 version.
Looking for the alternative property to support multiple languages, but not all languages again.
When sonar.language is omitted then the scanner analyzes all kind of supported sources (depends on installed plugins). You only need to correctly configure sonar.sources (your java and kotlin sources have to be included).
and it defines kotlin key, so the correct value is sonar.language=java,kotlin.
Unfortunately, not working for me. It says configure the plugin with “java,kotlin”. I guess sonarqube is treating the plugin name as “java,kotlin”, not as 2 plugins
Better idea is to configure correctly sonar.sources and sonar.inclusions, for example:
sonar.sources=src/
Works fine when I mention “src/java” or “src/…” etc. I am worried about huge code bases, android modules etc.
sonar.inclusions=.java,.kt
If I include this property along with sonar.sources, then indexing failing, so dashboard doesn’t show results or code.
Task :app:sonarqube
Putting task artifact state for task ‘:app:sonarqube’ into context took 0.0 secs.
No variant name specified to be used by SonarQube. Default to ‘debug’
Up-to-date check for task ‘:app:sonarqube’ took 0.0 secs. It is not up-to-date because:
Task has not declared any outputs.
No variant name specified to be used by SonarQube. Default to ‘debug’
User cache: /Users/ramprasad/.sonar/cache
Publish mode
Load global settings
Load global settings (done) | time=583ms
Server id: *********
User cache: /Users/ramprasad/.sonar/cache
Load/download plugins
Load plugins index
Load plugins index (done) | time=531ms
Load/download plugins (done) | time=586ms
Loaded core extensions:
Default locale: “en_US”, source code encoding: “UTF-8” (analysis is platform dependent)
Process project properties
Load project repositories
Load project repositories (done) | time=521ms
Load quality profiles
Load quality profiles (done) | time=480ms
Load active rules
Load active rules (done) | time=4617ms
Load metrics repository
Load metrics repository (done) | time=392ms
SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project.
Project key: SK:test
Project base dir: /Users/ramprasad/kotlin/SonarTest/app
------------- Scan Sonar Kotlin
Load server rules
Load server rules (done) | time=728ms
Base dir: /Users/ramprasad/kotlin/SonarTest/app
Working dir: /Users/ramprasad/kotlin/SonarTest/app/build/sonar
Source paths: src/main
Test paths: src/test/java, src/androidTest/java
Source encoding: UTF-8, default locale: en_US
Index files
Included sources: .java .kt
Excluded sources: .java .kt
Included tests: .java .kt
0 files indexed
CPD calculation finished
Task :app:sonarqube
27 files ignored because of inclusion/exclusion patterns
Sensor SonarJavaXmlFileSensor [java]
Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
Sensor Zero Coverage Sensor
Sensor Zero Coverage Sensor (done) | time=0ms
Sensor CPD Block Indexer
Sensor CPD Block Indexer (done) | time=0ms
No SCM system was detected. You can use the ‘sonar.scm.provider’ property to explicitly specify it.
Calculating CPD for 0 files
Analysis report generated in 117ms, dir size=31 KB
Analysis reports compressed in 9ms, zip size=7 KB
Analysis report uploaded in 443ms
ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=SK%3Atest
Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
More about the report processing at http://localhost:9000/api/ce/task?id=*****
Task total time: 10.967 s
:app:sonarqube (Thread[Task worker for ‘:’ Thread 2,5,main]) completed. Took 14.162 secs.
I’m not SonarSourcer, but I think the answer is “never”. This parameter is deprecated since SonarQube 4.5 because by default most people want to scan all source code. If you want to exclude something, then you have to use Exclusions / Inclusions analysis parameters.
You excluded all files which you try to scan. That’s the reason why you have zero code on the dashboard.
I am a SonarSourcer. Adam is right. There is no intent to “fix this” because it’s not broken. The parameter by definition and intent accepts only one language which is why it was deprecated when we introduced multi-language analysis. If you want to limit what’s analyzed, then you need to do it with exclusions.
Alternately, you could edit the file suffixes for the languages you want to ignore so that files of those languages won’t be picked up, but this would really be a hack.
Logs are showing as excluded, but I have not used “exclusions”, instead used “inclusions” with “*.java,*kt”. We can observe this in my above comment “Configuration” section.
Sonar will analyse only few directories by mentioning the paths in “sonar.sources”
Once the above source directory is considered, I can mention “exclusions” file patterns to filter the files of above directories from analysis.
Once the above source directory is considered, I can mention “inclusions” file patterns to include only the pattern matched files of above directories for analysis.
Sorry for lengthy comment. I would like to correct if anything is missing.
sonar.sources - Comma-separated paths to directories containing source files.
sonar.inclusions - Comma-delimited list of file path patterns to be included in analysis. When set, only files matching the paths set here will be included in analysis.
sonar.exclusions - Comma-delimited list of file path patterns to be excluded from analysis.
Your inclusion patterns are wrong. What you’ve included is anything with a .java or .kt extension at the root of your project, which I’m guessing is not where your files actually are. I believe at a minimum you want **/*.java &etc. instead. Beyond that, you’ve provided the same inclusions for both tests and sources, which is just going to lead to heartache and confusion. So you probably ought to narrow that path down before you apply the ** (any number of directories) in your pattern.
Seems, because of “test.sources” property the source code is getting removed and I have used “**/.java, **/.kt” by removing “sonar.sources” now. Now it seems working fine.
Need to check the usage of “test.sources” for future purpose.
Thanks for support @agabrys