After updating Kotlin from 1.8.10 to 1.8.20 we're ...
# gradle
x
After updating Kotlin from 1.8.10 to 1.8.20 we're suddenly seeing build errors like this:
Execution failed for task ':jar'.
> Entry ....class is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.5.1/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.
We know we can add a duplicate strategy...
Copy code
tasks.withType(Jar) {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
...but we'd like to understand why this is happening in the first place. What changed between 1.8.10 and 1.8.20 that's causing duplicate class files to be generated? We're using Gradle 7.5.1, in case it matters.
t
which Kotlin plugin are you applying?
x
Also 1.8.20
t
which id of Kotlin plugin? Like "org.jetbrains.kotlin.jvm", "org.jetbrains.kotlin.android", etc...
x
We're using the legacy plugin syntax:
Copy code
buildscript {
    ...
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

...

apply plugin: 'kotlin'
where
$kotlin_version
is set in
gradle.properties
.
I tried changing the
apply
line to:
Copy code
apply plugin: "org.jetbrains.kotlin.jvm"
as documented here, and I get the same behavior: it works in 1.8.10, but complains about duplicate class files in 1.8.20.
It looks like the issue is related to the atomicfu plugin. We were applying it like this (again, legacy plugin syntax):
Copy code
classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version" // atomicfu_version = 0.20.1
...
apply plugin: 'kotlinx-atomicfu'
We are no longer using the features of this plugin, so I removed it from our build, and the duplicate class error is gone.