We are currently running SonarQube community version 22.214.171.124698 in Kubernetes using a custom docker image based on the official image. I’ve started using context receivers in my Kotlin code (https://github.com/Kotlin/KEEP/issues/259); this is an experimental features, but is very useful and is seeing quite wide use. Is there any SonarQube version which supports this feature?
I run scan my code using the sonarqube gradle plugin and am currently getting a
Unable to parse file error which points to a line of code containing the
context keyword before a function declaration.
Could you, please, provide a simple reproducer for the issue? Exact compiling code snippet and log output. Also, since this is an experimental feature, we don’t guarantee to support it properly. However, we’ll try to have a look, at what we can do to support it.
I’ve uploaded a small project which demonstrates the problem to my github account at GitHub - wfhartford/sonar-kotlin-context: Example of Kotlin context receivers with Sonarqube analysis
./gradlew sonar task using my SonarQube installation results in the following message:
> Analyzing /home/wesley/work/projects/sonar-kotlin-context/src/main/kotlin/main.kt led to an exception.
The original exception message was: null
Running detekt ‘1.19.0’ on Java ‘17.0.7+7-Ubuntu-0ubuntu122.04.2’ on OS ‘Linux’>
If the exception message does not help, please feel free to create an issue on our GitHub page.
Using an extension function instead of a context receiver for the
launchHello() function (as described in code comments) allows the analysis to complete normally.
As mentioned in by initial post, we are using a slightly out of date installation of SonarQube. We would be willing to upgrade SonarQube, but if possible, I’d like to upgrade to a version with context receiver support.
I’ve just checked your example on the latest build of the Kotlin analyzer and the analysis was successful.
Indeed you’re using a quite old LTS version that has only Kotlin 1.4 compiler there. So if you upgrade to SQ 10.2 once it’s released, you should be safe. I can also double-check if this is fine on the latest LTS 9.9, if you’re going to use LTS version