Kotlin code not detected

Hi,
I cannot analyze Kotlin code correctly, as a sensor is not detecting it. I’m executing

mvn clean install  sonar:sonar -Dsonar.login=xxx  -Dsonar.projectKey=123 -Dsonar.projectName="123"
...
output
...
[INFO] Project configuration:
[INFO] 26 files indexed
[INFO] 0 files ignored because of scm ignore settings
[INFO] ------------- Run sensors on module DEVOPS / dsl-microservice-pipelines
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=34685ms
[INFO] Sonargraph Integration: Created 55 predefined and 0 custom metric(s)
[INFO] Sensor C# Project Type Information [csharp]
[INFO] Sensor C# Project Type Information [csharp] (done) | time=3ms
[INFO] Sensor C# Analysis Log [csharp]
[INFO] Sensor C# Analysis Log [csharp] (done) | time=12ms
[INFO] Sensor C# Properties [csharp]
[INFO] Sensor C# Properties [csharp] (done) | time=0ms
[INFO] Sensor HTML [web]
[INFO] Sensor HTML [web] (done) | time=3ms
[INFO] Sensor Text Sensor [text]
[INFO] 0 source files to be analyzed
[INFO] 0/0 source files have been analyzed
[INFO] Sensor Text Sensor [text] (done) | time=4ms
[INFO] Sensor VB.NET Project Type Information [vbnet]
[INFO] Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
[INFO] Sensor VB.NET Analysis Log [vbnet]
[INFO] Sensor VB.NET Analysis Log [vbnet] (done) | time=13ms
[INFO] Sensor VB.NET Properties [vbnet]
[INFO] Sensor VB.NET Properties [vbnet] (done) | time=0ms

26 files indexed and 0 files analyzed.
On the UI of sonarqube I see only pom.xml scrapped, the .kt files are not detected. Any idea hot to run the analysis successfully?

Thanks,

Of cors I’ve tried to add to the command

-Dsonar.sources=.

or

-Dsonar.sources=src

the same result.

Hi,

The source files the Maven scanner provides to analysis are Java files. Specifically, .java files in src/main/java. If your Kotlin sources aren’t filed there, then I don’t believe setting -Dsonar.sources=src is going to help.

Alternately, you could switch to Gradle, which I suppose is the default expectation for Kotlin analysis.

 
Ann

Hi,

maybe this thread helps

The mentioned Jira ticket [MSONAR-190] - Jira is closed on 30 August 2023, so i guess there will be a new version of the Sonarqube Maven plugin soon.

Gilbert

1 Like

Hi,
I’ve tried the

-Dsonar.sources=src 

but the same result. As our kotlin code is actually the teamcity pipelines code it have to be maven. I’ll try other plugins like detekt or so. Maybe it will help.
And @Rebse - maybe new version of the scanner will change something.

Thanks,

1 Like

Moving your kotlin files to src/main/somefolder combined with -Dsonar.source=src/main may help,
it worked for our angular files.
It seems that src alone or ‘.’ is ignored by the Sonarqube Maven plugin !?

1 Like

Indeed the DSL code (written in kotlin) for the teamcity pipelines should be placed into ./teamcity folder and originally I’s sure only the . is an issue with detecting the kotlin files but now I’m trying other repo, where code is “traditionally” in ./src
mvn-execution.log (44.6 KB)
Files are indexed but not analyzed :expressionless: … The only file detected by sonar (visible on its UI in appropriate project is pom.xml)

You may try with the latest version of the Sonarqube Maven Plugin sonar-maven-plugin:3.9.1.2184
From the logs i see you use sonar-maven-plugin:3.8.0.2131 which is rather old.

I’ve also tried the newest maven but - hey - I’ve solved the issue. The reason was … trivial.
On the UI Administration / Configuration / Languages / Kotlin there is only one parameter to set: “File suffixes” and it’s described as:

List of suffixes for files to analyze.

I’ve read this as comma separated list … and put there value

.kt,.kts

After changing it to two separate items of the list it started working :slight_smile:

Thanks for your assistance!

Case closed :slight_smile:

1 Like

Gotcha :slight_smile: One could use the settings of other languages as example, but an additional entry, i.e. ‘One entry per line’ or similar won’t hurt, as there are also comma-separated values.