Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running detekt on JVM target (in KMP project) doesn't run against the commoon source set #7073

Open
xgouchet opened this issue Mar 20, 2024 · 2 comments

Comments

@xgouchet
Copy link

Expected Behavior

When applying Detekt on a KMP project, with commonMain and jvmMain source sets, the task detektJvmMain should apply rule detection to all source files contributing to the JVM target, that is, both commonMain and jvmMain.

Observed Behavior

In the case mentionned above, the task detektJvmMain only applies rule detection to the kotlin files in the jvmMain source set, but not the shared files from the commonMain source set.

Steps to Reproduce

Project

Sample project attached : sample.zip.
If not available, just create a simple new KMP project with the following files:

build.gradle.kts

plugins {
    kotlin("multiplatform") version "1.9.22"
    id("io.gitlab.arturbosch.detekt") version ("1.23.5")
}

kotlin {
    jvm {
        jvmToolchain(17)
        withJava()
    }
}

repositories {
    google()
    mavenCentral()
}

src/commonMain/kotlin/CommonClass.kt

class CommonClass {
    val my_property: Int = 0
}

src/jvmMain/kotlin/JvmClass.kt

import java.util.Date

class JvmClass {
    val my_property: Date = Date()
}

Reproduction test

  1. run the detektMetadataMain gradle task
    • notice it finds (at least) one issue in the CommonClass (i.e.: Variable names should match the pattern: [a-z][A-Za-z0-9]* [VariableNaming])
  2. run the detektJvmMain gradle task
    • notice it only finds issues in the JvmClass (at least: Variable names should match the pattern: [a-z][A-Za-z0-9]* [VariableNaming])

Context

Some of our custom rules rely on type resolution which is only availbale when running against the JVM target.

Your Environment

  • Version of detekt used: 1.23.5
  • Version of Gradle used (if applicable): 8.4
  • Gradle scan link (add --scan option when running the gradle task): https://gradle.com/s/u467js5p4dob2
  • Operating System and version: Mac OS Ventura 13.6.4
  • Link to your project (if it's a public repository):
@xgouchet xgouchet added the bug label Mar 20, 2024
@eygraber
Copy link
Contributor

I addressed this in a convention plugin that I use.

See #6634 (comment) and #6634 (comment) for some pros and cons to this approach

@xgouchet
Copy link
Author

Thanks a lot for your insights @eygraber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants