Kotlin: Getting "Copying or archiving duplicate paths..." deprecation warnings when building plugin

Answered

I'm writing my plugin in Kotlin, and using a build.gradle.kts file to setup the Gradle build.

While in general I don't find converting from Java to Kotlin difficult at all, the differences between build.gradle and build.gradle.kts files confuse me, and sample build.gradle.kts dealing with this issue aren't easy to find.

Here are the warnings:

> Task :prepareSandbox
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: "Ligatures Limited/lib/kotlin-stdlib-1.3.72.jar". Explicitly set the duplicates strategy to 'DuplicatesStrategy.INCLUDE' if you want to allow duplicate paths.
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: "Ligatures Limited/lib/annotations-13.0.jar". Explicitly set the duplicates strategy to 'DuplicatesStrategy.INCLUDE' if you want to allow duplicate paths.
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: "Ligatures Limited/lib/kotlin-stdlib-common-1.3.72.jar". Explicitly set the duplicates strategy to 'DuplicatesStrategy.INCLUDE' if you want to allow duplicate paths.

I tried this as my best guess at a Kotlin version of a Java fix I found:

val jar by tasks.getting(Jar::class) {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

This doesn't cause any problems, but it doesn't fix anything either. It doesn't help that I don't really know Gradle very well, I'm just trying to modify the Kotlin plugin template generated for me by IDEA.

What's the correct way to fix this problem?

7 comments
Comment actions Permalink

What about the following syntax:

tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

You may find more details in the Configuring tasks section in the Gradle Docs.

0
Comment actions Permalink

It tried that once before, and instead of it helping, I get LOTS MORE of those warnings instead, at least on the first rebuild after changing the file. Does the position in the script matter? Here's the entire script:

plugins {
id("org.jetbrains.intellij") version "0.4.20"
java
kotlin("jvm") version "1.3.72"
}

group = "com.foobar"
version = "1.0.0"

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("com.google.code.gson:gson:2.8.6")
}

intellij {
version = "IC-2020.1.2"
updateSinceUntilBuild = false
}

configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs = listOf("-Xjvm-default=enable")
}

compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs = listOf("-Xjvm-default=enable")
}
}

tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") {
changeNotes("""
Blah, blah...
"""
)
}
0
Comment actions Permalink

I just noticed I put this in the wrong forum. I meant Plugin Developers, not Plugin Users.

0
Comment actions Permalink

I didn't get any errors when using exactly the same script:

08:21:53: Executing task 'runIde'...

> Task :compileKotlin UP-TO-DATE
> Task :compileJava NO-SOURCE
> Task :patchPluginXml UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :inspectClassesForKotlinIC UP-TO-DATE
> Task :instrumentCode UP-TO-DATE
> Task :postInstrumentCode
> Task :jar UP-TO-DATE
> Task :prepareSandbox UP-TO-DATE

> Task :runIde

Which Gradle Wrapper version do you use?

0
Comment actions Permalink
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

The errors aren't coming on the runIde task, by the way, but buildPlugin.

0
Comment actions Permalink

Nor runIde or buildPlugin makes any problems. I use Gradle Wrapper 6.5.1

0
Comment actions Permalink

I updated the Gradle wrapper version, but it didn't help. For a moment I thought the wrapper update fixed the problem, but to make sure I ran the clean task, ran the build again, and the errors were back.

10:16:47: Executing task 'buildPlugin --warning-mode all'...

> Task :compileKotlin
> Task :compileJava NO-SOURCE
> Task :patchPluginXml
> Task :processResources
> Task :classes
> Task :inspectClassesForKotlinIC
> Task :instrumentCode
> Task :postInstrumentCode
> Task :jar

> Task :prepareSandbox
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: "Ligatures Limited/lib/kotlin-stdlib-1.3.72.jar". 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.5.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: "Ligatures Limited/lib/annotations-13.0.jar". 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.5.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: "Ligatures Limited/lib/kotlin-stdlib-common-1.3.72.jar". 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.5.1/userguide/upgrading_version_5.html#implicit_duplicate_strategy_for_copy_or_archive_tasks_has_been_deprecated

> Task :buildSearchableOptions
Starting searchable options index builder
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to field java.awt.event.InvocationEvent.runnable
WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2020-07-28 10:16:52,036 [ 715] WARN - j.internal.DebugAttachDetector - Unable to start DebugAttachDetector, please add `--add-exports java.base/jdk.internal.vm=ALL-UNNAMED` to VM options
2020-07-28 10:16:52,675 [ 1354] WARN - ConfigurableExtensionPointUtil - ignore deprecated groupId: language for id: preferences.language.Kotlin.scripting
2020-07-28 10:16:53,251 [ 1930] WARN - nSystem.impl.ActionManagerImpl - keymap "Xcode" not found [Plugin: com.intellij]
2020-07-28 10:16:54,148 [ 2827] WARN - Container.ComponentManagerImpl - Do not use constructor injection (requestorClass=com.android.tools.idea.sdk.AndroidSdks)
Searchable options index builder completed

> Task :jarSearchableOptions
> Task :buildPlugin

BUILD SUCCESSFUL in 12s
11 actionable tasks: 11 executed
10:17:00: Task execution finished 'buildPlugin --warning-mode all'.
0

Please sign in to leave a comment.