Gradle 6, Gradle TestKit and DuplicatesStrategy.INCLUDE warning

Viewed 4393

Since upgrading Gradle to version 6, I noticed new warnings related to functional tests I've implemented with TestKit. It is clear to me how to get rid of them. What is not clear is why they appear in the first place, and how would they be relevant in the context of functional testing.

Here is the smallest project I could think of to reproduce the issue:

https://github.com/automatictester/gradle-issure-repro

Relevant build.gradle:

plugins {
    id 'java'
    id 'java-gradle-plugin'
}

sourceSets {
    functionalTest {
        java {
            srcDir file('src/functionalTest/java')
        }
        resources {
            srcDir file('src/functionalTest/resources')
        }
        compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
        runtimeClasspath += output + compileClasspath
    }
}

task functionalTest(type: Test) {
    testClassesDirs = sourceSets.functionalTest.output.classesDirs
    classpath = sourceSets.functionalTest.runtimeClasspath
}

check.dependsOn functionalTest

gradlePlugin {
    testSourceSets sourceSets.functionalTest
}

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    testImplementation gradleTestKit()
    testImplementation 'org.testng:testng:7.1.1'
}

// uncomment to get rid of warnings
//processFunctionalTestResources {
//    duplicatesStrategy = DuplicatesStrategy.INCLUDE
//}

You can reproduce the issue with:

./gradlew clean functionalTest --warning-mode all

Output:

Copying or archiving duplicate paths with the default duplicates strategy has been deprecated. This is scheduled to be removed in Gradle 7.0. Duplicate path: "build.gradle". Explicitly set the duplicates strategy to 'DuplicatesStrategy.INCLUDE' if you want to allow duplicate paths. Consult the upgrading guide for further information: https://docs.gradle.org/6.2.1/userguide/upgrading_version_5.html#implicit_duplicate_strategy_for_copy_or_archive_tasks_has_been_deprecated
Copying or archiving duplicate paths with the default duplicates strategy has been deprecated. This is scheduled to be removed in Gradle 7.0. Duplicate path: "settings.gradle". Explicitly set the duplicates strategy to 'DuplicatesStrategy.INCLUDE' if you want to allow duplicate paths. Consult the upgrading guide for further information: https://docs.gradle.org/6.2.1/userguide/upgrading_version_5.html#implicit_duplicate_strategy_for_copy_or_archive_tasks_has_been_deprecated

BUILD SUCCESSFUL in 1s
6 actionable tasks: 6 executed

It is basically printing a warning per every single file found in src/functionalTest/resources.

Can someone help me understand what is the risk this warning is trying to protect me from, and why something relevant for copy or archive tasks shows up for functional tests configuration set up according to the official guide?

https://docs.gradle.org/6.2.1/userguide/test_kit.html

1 Answers

Your (derived) task processFunctionalTestResources is of type Copy, which has the DuplicatesStrategy property. Starting at Gradle 6, it's showing a warning if not explicitly defined.

I now encounter this myself for war and ear tasks.

From the second link:

Archive tasks Tar and Zip by default allow multiple entries for the same path to exist in the created archive. This can cause "grossly invalid zip files" that can trigger zip bomb detection.

Related