Detekt: 1.2.1 breaks the build with: unresolved reference: detekt

Created on 1 Dec 2019  路  4Comments  路  Source: detekt/detekt

Expected Behavior

I have a project using detekt 1.2.0:
https://github.com/jcornaz/kwik/tree/3ba15e2fd54228ae5214f45b39a5977a1af14b7e

I would like to update detekt to version 1.2.1. Since it is a patch I expect the update to be possible without any failure.

Observed Behavior

If I update detekt version to 1.2.1 the build breaks with the following message:

Script compilation errors:

  Line 06: import io.gitlab.arturbosch.detekt.detekt
                                              ^ Unresolved reference: detekt

  Line 72:     detekt {
               ^ Unresolved reference: detekt

  Line 73:         input = files(
                   ^ Unresolved reference: input

  Line 77:         buildUponDefaultConfig = true
                   ^ Unresolved reference: buildUponDefaultConfig

  Line 78:         config = files("$rootDir/detekt-config.yml")
                   ^ Unresolved reference: config

Steps to Reproduce

Setup working version:

git clone [email protected]:jcornaz/kwik.git
cd kwik
git checkout 3ba15e2fd54228ae5214f45b39a5977a1af14b7e
./gradlew detekt # Observe success

Then in line 15 of build.gradle.kts replace 1.2.0 by 1.2.1.

Finally, observe the problem:

./gradlew detekt

Context

I want to update detekt from version 1.2.0 to 1.2.1.

Your Environment

  • Version of detekt used: 1.2.1
  • Version of Gradle used: 6.0.1
  • Operating System and version: Linux version 5.3.12-1-MANJARO
  • Link to your project: https://github.com/jcornaz/kwik
bug gradle

Most helpful comment

@jcornaz I've worked out what the issue is. 1.2.1 removed this Gradle extension: https://github.com/arturbosch/detekt/blob/1.2.0/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/KotlinExtension.kt

It was there to allow the type-safe accessors to work in Gradle Kotlin DSL, which is why removing it causes failures in the build when type-safe accessors are not available.

I see two options:

  1. Add the extension back to the plugin with a deprecation warning, advising that there's a misconfiguration in the build file and linking to https://docs.gradle.org/current/userguide/kotlin_dsl.html
  2. Describe how the Gradle build files should be corrected (an easy way is to remove apply false against detekt in the plugins block - not strictly correct if you don't want to apply the plugin to the root project, but it restores type-safe accessors. Other options are to apply the plugin in individual module build files or use the standard API)

It probably does no harm to leave the extension in place, though it's not documented in the Gradle Kotlin DSL primer so it's probably not a supported workaround. Adding back with a deprecation message seems the best option. I'll open a PR.

I can also confirm I don't see any warning if I use config = with detekt: 1.2.1.

@1951FDG @jcornaz my mistake, the deprecation wasn't on config in the extension, but in the tasks. It doesn't affect the detekt {} block.

All 4 comments

Looking at your build file you should be able to remove import io.gitlab.arturbosch.detekt.detekt and get it working again. Sorry about that, we should have had a deprecation message where that extension was being used.

You'll also need to change config = files("$rootDir/detekt-config.yml") to config.setFrom( files("$rootDir/detekt-config.yml")). This one should have triggered a deprecation warning in 1.2.0 for direct usage of config =. If it didn't can you please advise?

@3flex

Thanks for your support.

However, I couldn't get it working again. You can find a version with the changes you told me to do at the commit: d9c6c919675ac729658dfebbc73ad6c011f4b4c2 of the project.

This one should have triggered a deprecation warning in 1.2.0 for direct usage of config =

No, I confirm I don't see any warning if I use config = with detekt: 1.2.0. (Absence of warning is observable at commit 92ea258094e577de6adccefcfe91f35a6d0fdc54 of the project).

I can also confirm I don't see any warning if I use config = with detekt: 1.2.1.

@jcornaz I've worked out what the issue is. 1.2.1 removed this Gradle extension: https://github.com/arturbosch/detekt/blob/1.2.0/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/KotlinExtension.kt

It was there to allow the type-safe accessors to work in Gradle Kotlin DSL, which is why removing it causes failures in the build when type-safe accessors are not available.

I see two options:

  1. Add the extension back to the plugin with a deprecation warning, advising that there's a misconfiguration in the build file and linking to https://docs.gradle.org/current/userguide/kotlin_dsl.html
  2. Describe how the Gradle build files should be corrected (an easy way is to remove apply false against detekt in the plugins block - not strictly correct if you don't want to apply the plugin to the root project, but it restores type-safe accessors. Other options are to apply the plugin in individual module build files or use the standard API)

It probably does no harm to leave the extension in place, though it's not documented in the Gradle Kotlin DSL primer so it's probably not a supported workaround. Adding back with a deprecation message seems the best option. I'll open a PR.

I can also confirm I don't see any warning if I use config = with detekt: 1.2.1.

@1951FDG @jcornaz my mistake, the deprecation wasn't on config in the extension, but in the tasks. It doesn't affect the detekt {} block.

Was this page helpful?
0 / 5 - 0 ratings