If you are now getting this error, its probably not the fixed bug described above (in Gradle 8.2.1 anyway). Instead, you may be actually including the same source files in multiple targets, using something like:
sourceSets {
val AndroidMain by getting {
dependencies {
srcDirs("src/your_common_files")
}
}
val jvmMain by getting {
dependencies {
srcDirs("src/your_common_files")
}
}
Gradle does not like this extremely common code reuse technique, possibly because gradle was designed to frustrate innocent developers :-).
Instead, gradle wants you to make a separate "sourceset" and then depend on it. Almost but not quite like this:
sourceSets {
create("commonJvm") {
kotlin.srcDirs("src/commonJvm")
}
val androidMain by getting {
dependencies {
sourceSets.named("commonJvm")
}
}
val jvmMain by getting {
dependencies {
sourceSets.named("commonJvm")
}
}
}
Instead, use this:
sourceSets {
create("commonJvm") {
kotlin.srcDirs("src/commonJvm")
}
val androidMain by getting {
dependsOn(sourceSets.named("commonJvm").get())
dependencies {
}
}
val jvmMain by getting {
dependsOn(sourceSets.named("commonJvm").get())
dependencies {
}
}
}
I guess its not a "dependency" but it just "depends on" the common source set! /s
Makes sense to someone I guess?!?!
Personally, I think that all 3 of these ways ought to work, so I'm leaving this cookie crumb to save you 4 hours of head banging pain.
Note that you could also "cheat" and just use symlinks. But mswindows does not like that.