Which is the alternative property of SonarQube gradle property ''language" which is deprecated?

Hi Team,

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.

Looking forward for great community support.

Regards,
Ram

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).

Thanks for quick response Adam.

Yeah, the link says about how to support all languages. I have tried this already. But I want to support quality check only on java and kotlin.

“sonar.language” prop is not allowing “java, kotlin” as input.

Is there any way to supply only 2 languages?

Yeah, sonar.sources is one way to impose. But for huge code bases it is handy way. So looking for best solution if possible.

I don’t know which plugin do you use to analyze Kotlin sources. I found this:

and it defines kotlin key, so the correct value is sonar.language=java,kotlin.

Better idea is to configure correctly sonar.sources and sonar.inclusions, for example:

sonar.sources=src/
sonar.inclusions=*.java,*.kt

Read more about Exclusions / Inclusions analysis parameters.

1 Like

Correct, I am using the same plugin.

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.

Yes, you are right. I forgot about that.

You can set more directories:

sonar.sources=src/java,src/kotlin

It is weird. Please add your configuration and logs.

1 Like

Do you have any plan/schedule to fix this?

Here is the configuration and logs.
Configuration:

sonarqube {
properties {
property “sonar.projectName”, “Sonar Kotlin”
property “sonar.projectKey”, “SK:test”
property “sonar.sources”, “src/main”
property “sonar.test”, “src/test”
property “sonar.inclusions”, “*.java, .kt"
property “sonar.test.inclusions”, "
.java, *.kt”
property “sonar.junit.reportPaths”, “./build/test-results/debug”
property “sonar.jacoco.reportPaths”, “./build/jacoco/testDebugUnitTest.exec”
}
}

Logs:

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.

2 Likes

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.

Ann

2 Likes

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.

Thanks for response.

  • I guess “exclusions” didn’t work for my case. Here is the configuration, logs, dashboard screenshots.
    exclusions_testing.txt (4.8 KB)
  • Another observation is, other source folder “src/androidTest/java/com/test/sonartest” also included in analysis, which should not be the case.

My understanding is

  • 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.

Yeah, I better do not go with this approach.

Exclusions could be also set in SonarQube Web UI (I have SonarQube 7.1):

  • globaly:
    • Administration → Analysis Scope → Global Source File Exclusions
    • Administration → Analysis Scope → Source File Exclusions
  • per project:
    • open project → Administration → Analysis Scope → Source File Exclusions

Please verify if nobody set those parameters.

I think you are right. From the documentation:

  • 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.
1 Like

Hi,

Backing up to your initial message

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.

HTH,
Ann

@agabrys
Thanks for above message.

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

1 Like

@ganncamp
Oh, yeah. I found the same and fixed it. Posted in this thread.
Thanks for support!!