Error: Entry <class> is duplicate but no duplicate handling strategy has been set

I have a module with Java and Scala. Project structure is like this:


When I compile I get (%90 of the times) the error
Execution failed for task ‘:altair.dnn.common:jar’
Entry .class is a duplicate but no duplicate handling strategy has been set. Please refer to Copy - Gradle DSL Version 7.5.1 for details.

I don’t have any Copy in my Gradle file and I don’t see a Copy task.
The class is from Scala - it is not used by Java code (and can’t, since it compiles before) , and yet I see the .class file both in build/classes/java and build/classes/scala

Sometimes when I manually remove the build/classes directory it does pass.

My build.gradle is:

plugins {
    id 'altair.dnn.conv.scala-library-conventions'
	id 'jacoco'
    id 'org.jetbrains.kotlin.jvm' version '1.8.0'

tasks.register('coverageTest') {
    // jacoco must run only after 'test' task (since it looks for results in specific location)
    // so coverageTest must run 'test' task and not e.g. run the tests itself
    dependsOn test
    finalizedBy jacocoTestReport

jacoco {
    toolVersion = "0.8.7"

dependencies {
	implementation ''
	implementation 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.1'
	implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

Just a shot in the dark, but do you maybe have build/classes/java configured as output directory of your IDE and your IDE compiles the Scala files then also to that directory, and after that the build fails with this message as then the class files are in both, build/classes/java and build/classes/scala?

You should either delegate building and running to Gradle, which for IntelliJ for example is the default anyway, or at least configure your IDE to not place files into output directories of tasks which then disturbs up-to-date checks, create corrupt cache entries, makes builds fail, …

I closed my IntelliJ, and executed gradlew from command line. Still the same error

Of course.
Closing IntelliJ does not delete the .class files it compiled to build/classes/java/main that are disturbing the Gradle build.