detekt/sonar-detekt

No input file found, No detekt issues will be imported on this file.

overfullstack opened this issue · 3 comments

Hi! I have a multi-module gradle project, which has a Sonar intergration, and I wish to use Detekt metrics inside Sonar. Here is my root gradle build file sonar entry. I have setup sources and test for all the subprojects.

property("sonar.sources", "src/main")
property("sonar.tests", "src/test")

But when I run gradle sonarqube task, I keep getting errors like:

No input file found for /Users/gopala.akshintala/code-clones/my-github/vader-root/vader/build/generated/sources/delombok/java/main/org/revcloud/vader/runner/Utils.kt. No detekt issues will be imported on this file.

And I don’t see any detekt related errors.
Note: I am using lombok for some modules, so I even tried this:

property(
  "sonar.sources",
  the<SourceSetContainer>()["main"].allJava.srcDirs.filter { it.exists() }.joinToString(",")
)
property(
  "sonar.tests",
  the<SourceSetContainer>()["test"].allJava.srcDirs.filter { it.exists() }.joinToString(",")
)

but I keep getting the same error with file path being different (pointing to generated, so I guess this is not lombok specific)

No input file found for /Users/gopala.akshintala/code-clones/my-github/vader-root/vader/build/generated/sources/delombok/java/main/org/revcloud/vader/runner/Utils.kt. No detekt issues will be imported on this file.

Please help!

Can't really help you at this stage as this looks really specific to your setup.
If anyone has more experience with sonar please chime in 🙏

Thanks @cortinico, I found the problem. detekt.xml has absolute paths, i.e. /home/jenkins/workspace/<workspace name>/src/main/kotlin/… but the workspace where the build runs is volume-mounted inside a sonarqube sidecar, where the workspace is at /tmp/project/src/main/kotlin/…. I resolved it by placing this line in my jenkins file:

  stage('Sonarqube') {
    sh "sed -i 's/${WORKSPACE.replace("/","\\/")}/\\/tmp\\/project/' build/reports/detekt/detekt.xml"
    sonarqube()
  }

Some feedback: I feel detekt should use relative path instead of absolute paths. This can happen in any environment.

Some feedback: I feel detekt should use relative path instead of absolute paths. This can happen in any environment.

We technically support relative paths inside detekt:

https://detekt.github.io/detekt/gradle.html#kotlin-dsl-3

    // Specify the base path for file paths in the formatted reports. 
    // If not set, all file paths reported will be absolute file path.
    basePath = projectDir

I'm not sure if using detekt-gradle-plugin and specifying the basePath will work correctly on sonar-kotlin.

Anyway I'm closing as the root issue was solved. Please give it a try with basePath and if that doesn't work, you can open an issue for a feature request for better relative-path support.