gradlebuild.gradle

How to integrate duplicate handling strategy in application plugin


I am using the application plugin in one of my projects. After upgrading to Gradle 7.x I got the failure:

        Execution failed for task ':xyz:distTar'.
        > Entry xyz-1.0/lib/jaxb-core-3.0.1.jar is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.3.3/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.

I found a stack overflow post related to that Gradle 7 task ':distTar' is a duplicate but no duplicate.... But the recommendation to incorporate...

tasks.withType<Tar> {
   duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

tasks.withType<Zip>{
   duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

did not work out for. It ended in the failure:

A problem occurred evaluating project ':integration-test'.
> Could not get unknown property 'withType' for task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.

My build.gradle looks basically like this...

apply plugin: 'java'
apply plugin: 'application'

version = '1.0'
sourceCompatibility = 11
targetCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {
    implementation(
        ...
    )
}

application {
    mainClassName = 'a.b.c.XYZ'
}

Any idea?


Solution

  • Shouldn't that be with regular parenthesis?

    tasks.withType(Tar) {
       duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    }
    

    or:

    tasks.withType(Tar.class).configureEach {
        duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    }