如何解决构建问题:条目 com/netflix/server/context/BiDirectional.class 是重复项但未设置重复处理策略

How fix a build problem: Entry com/netflix/server/context/BiDirectional.class is a duplicate but no duplicate handling strategy has been set

我在尝试制作我的 java 应用程序的 fat jar 时遇到问题。 应用程序在使用IntelliJ时运行正常,没有出现运行错误。

错误:

Task :uberJar FAILED

失败:构建失败,出现异常。

Entry com/netflix/server/context/BiDirectional.class is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.0/dsl/org.gradle.api.file.CopySpec.html#org.gradle.api.file.CopySpec:duplicatesStrategy for details.

1 秒内构建失败 3 个可操作的任务:3

我的build.gradle:

    plugins {
    id 'java'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation 'io.netty:netty-all:4.1.66.Final',
            'io.reactivex.rxjava3:rxjava:3.1.0',
            'io.reactivex:rxnetty:0.4.20',
            'io.reactivex:rxjava:1.3.8',
            'io.reactivex:rxnetty:0.5.1',

            'io.netty:netty-codec-http:4.1.66.Final',

            'org.glassfish.jersey.core:jersey-server:2.7',
            'org.glassfish.jersey.containers:jersey-container-servlet-core:2.7',
            'org.glassfish.jersey.containers:jersey-container-jetty-http:2.7',

            'org.springframework:spring-core:5.3.8',
            'org.springframework:spring-context:5.3.8',
            'org.springframework:spring-beans:5.3.8',
            'org.springframework:spring-test:5.3.8',

            'com.netflix.karyon:karyon-governator:2.1.00-RC6',
            'com.netflix.karyon:karyon2-core:2.2.0-rc.2',

            'org.slf4j:slf4j-simple:1.7.0',
            'org.slf4j:slf4j-simple:1.7.0',

             'commons-io:commons-io:2.4'

}

task uberJar(type: Jar){

    archiveClassifier = 'uber'

    from sourceSets.main.output

    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.findAll { it.name.endsWith('jar') } .collect { zipTree(it) }
    }
    manifest.attributes(['Main-Class': '**the package omitted for security**.Main'])
}

我的期望是创建一个有效的 fat jar 文件...

gradle版本:7.0 JdK: 1.8

在此处查看此对话 https://try2explore.com/questions/10097082

修改您的 build.gradle 并设置重复策略。这将在 jar 中包含提到的文件。

task uberJar(type: Jar){

    archiveClassifier = 'uber'

    duplicatesStrategy = 'include' // <<---- addition

    from sourceSets.main.output

    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.findAll { it.name.endsWith('jar') } .collect { zipTree(it) }
    }
    manifest.attributes(['Main-Class': '**the package omitted for security**.Main'])
}

Java文档:https://docs.gradle.org/current/javadoc/org/gradle/api/file/DuplicatesStrategy.html