SonarCloud incorrectly reports import com.github.michaelbull.result.Result as an unused import under rule kotlin:S1128, even though the import is used by Kotlin’s type inference and is required for correct compilation and IDE behavior.
Any help appreciated!
Thanks,
Damien
ALM: Github CI: GitHub Actions Language: Kotlin SonarCloud Organization: thriveglobal Rule:kotlin:S1128 — “Unused imports should be removed” Scope: False positive Expected behavior: No issue raised Actual behavior: SonarCloud flags valid import as unused
@ganncamp We see the same problems, with many different types, probably around our update to Kotlin 2.3. We’re on Community Build v25.9.0.112764.
It complains about unused imports of types in generic definitions or annotations. The “pattern” is that it seems as if it gets Java’s `java.lang.*` and Kotlin’s `kotlin.*` built-in types mixed up that do not require an import, i.e. it complains about
import dagger.Module // probably mixed up with java.lang.Module
import org.koin.core.module.Module // again, probably mixed up with java.lang.Module
import my.app.package.domain.model.Error // probably mixed up with kotlin.Error or java.lang.Error
Right now the rule is creating so many false positives that we likely have to deactivate it.
Hi Ann, unfortunately my time is very limited, so I cannot come up with a public reproducer. Sonarqube is executed in a separate Jenkins build step where compilation happened in previous steps already, so I’d say yes, compilation happened before analysis.
I guess it has something to do with compilation skipping, just figured that we had compilation skipping enabled via `systemProp.sonar.gradle.skipCompile=true` in gradle.properties. What is the default now in the Gradle plugin, is compilation still implicitely kicked off when skipCompile=false or non-existant?
Are you asking about the sonar.gradle.skipCompile property? It was added to allow you to suppress the scanner’s normal triggering of compilation. So yes, omitting it would allow that compile to be triggered.
All tasks that produce output that should be included in the analysis need to be executed before the sonar task runs. Typically, these are compile tasks, test tasks, and Overview tasks. To meet these needs, the plugin adds a task dependency from sonar on test if the Java plugin is applied. Further task dependencies can be added as needed.
I take that to mean that compile will be triggered by default since test would necessarily require compilation, right? Plus Kotlin analysis needs compilation to be accurate.
But I’m going to flag the experts on this to be sure.