https://kotlinlang.org logo
#detekt
Title
# detekt
s

Stanislav Kral

03/17/2024, 11:23 AM
Hello, any ideas why
detekt
and
detektMain
give me different violations in one source file for a multimodule project?
Copy code
topnax@topnax-ryzen:<workdir>$ ./gradlew detekt

> Task :core-service:detekt FAILED
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:14:33: In most cases using a spread operator causes a full copy of the array to be created before calling a method. This may result in a performance penalty. [SpreadOperator]


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core-service:detekt'.
> Analysis failed with 1 weighted issues.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.

BUILD FAILED in 1s
1 actionable task: 1 executed
topnax@topnax-ryzen:<workdir>$ ./gradlew detektMain

> Task :core-service:detektMain FAILED
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:14:33: Used in this way a spread operator causes a full copy of the array to be created before calling a method. This may result in a performance penalty. [SpreadOperator]
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:11:5: Calling !! on a nullable type will throw a NullPointerException at runtime in case the value is null. It should be avoided. [UnsafeCallOnNullableType]
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:18:13: Calling !! on a nullable type will throw a NullPointerException at runtime in case the value is null. It should be avoided. [UnsafeCallOnNullableType]


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core-service:detektMain'.
> Analysis failed with 3 weighted issues.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.

BUILD FAILED in 1s
6 actionable tasks: 4 executed, 2 up-to-date
Root buildscript:
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import io.gitlab.arturbosch.detekt.Detekt

plugins {
	val kotlinVersion = "1.9.22"

	id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
    id("io.gitlab.arturbosch.detekt") version "1.23.5"

	kotlin("jvm") version kotlinVersion apply true
}

allprojects {
    apply(plugin = "io.gitlab.arturbosch.detekt")

    detekt {
        buildUponDefaultConfig = true
    }

    tasks.withType<Detekt>().configureEach {
        buildUponDefaultConfig = true
        reports {
            html.required = true
            // disabled until GitLab adds SARIF support
            // sarif.required = true
        }
    }

	repositories {
		mavenLocal()
		mavenCentral()
	}
}

subprojects {
	apply {
     ...
Any help would be appreciated. Thanks
m

marschwar

03/17/2024, 11:38 AM
The reason is that some rules require type resolution and and therefore are not enabled when running gradle detekt.
👍 1
s

Stanislav Kral

03/17/2024, 1:27 PM
And how come that the
UnsafeCallOnNullableType
is found with
detektMain
but not with
detekt
? How to make it so that both tasks find the violation?
m

marschwar

03/17/2024, 1:35 PM
Yes, there is no way to make it work. You should probably run detektMain and detektTest only.
s

Stanislav Kral

03/17/2024, 1:35 PM
Sorry, I previously missed this piece of docs. Thanks a lot. It's clear now.
👍 1
4 Views