Gradle“条目.classpath重复,但未设置重复处理策略”

yk9xbfzb  于 2022-11-14  发布在  其他
关注(0)|答案(7)|浏览(284)

我正在尝试构建一个gradle项目,但是当我尝试$ gradle build时,我得到了以下输出:

Starting a Gradle Daemon (subsequent builds will be faster)
> Task :jar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jar'.
> Entry .classpath 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.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s
4 actionable tasks: 2 executed, 2 up-to-date

在完成Get-ChildItem -Path ./ -Filter .classpath -Recurse -Force之后,我发现我的项目中甚至没有一个名为.classpath的文件。我该怎么办?

xdnvmnnf

xdnvmnnf1#

类似于@科恩的答案,我用EXCLUDE策略解决了我的问题;

tasks.withType<Jar>() {

    duplicatesStrategy = DuplicatesStrategy.EXCLUDE

    manifest {
        attributes["Main-Class"] = "MainKt"
    }

    configurations["compileClasspath"].forEach { file: File ->
        from(zipTree(file.absoluteFile))
    }
}
5w9g7ksd

5w9g7ksd2#

第一个问题是:如何创建一个新的策略?

o2gm4chl

o2gm4chl3#

我在使用Kotlin和gradle 7构建时遇到了同样的问题。将下面的代码添加到您的build.gradle.kts中可以解决这个问题。

tasks.withType<Jar> { duplicatesStrategy = DuplicatesStrategy.INHERIT }
nhjlsmyf

nhjlsmyf4#

如果您使用KotlinDSL和Gradle 7.0,则可能是由于该bug KT-46165,应在版本1.5.0中修复。

nwo49xxi

nwo49xxi5#

不知道你的情况与.classpath文件,你甚至找不到(因为我知道这个文件通常是创建与Eclipse IDE,我不使用)
但是,我在将Sping Boot 应用升级到Gradle 7.x时遇到了同样的错误。我的构建脚本有额外的资源处理任务来支持@..@样式的占位符(就像Spring Boot Maven构建一样,因为目前我支持项目中的两个构建系统,我需要它们表现得同等):

processResources {
    with copySpec {
        from 'src/main/resources'
        include 'my-app*.yml'
        include 'my-app*.yaml'
        include 'my-app*.properties'
        project.properties.findAll().each {
            prop ->
                if (prop.value != null) {
                    filter(ReplaceTokens, tokens: [(prop.key): prop.value.toString()])
                }
        }
    }
}

我在Gradle 7中遇到了同样的错误:
条目my-app.properties重复,但未设置重复处理策略,请参考https://docs.gradle.org/7.1/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy查看详细信息。
Gradle首先将未处理的文件复制到build/resources/main,然后尝试执行我的自定义processResources,并再次将文件复制到同一位置。
解决方案是将duplicatesStrategy = 'include'添加到with copySpec {}块。看起来之前Gradle已静默覆盖了重复项,因此没有问题。

5rgfhyps

5rgfhyps6#

请添加此
tasks.withType(Copy).all { duplicatesStrategy 'exclude' }
build.gradle文件中便把它解决了。

vjhs03f7

vjhs03f77#

检查您的应用程序级别构建gradle,并看看如果你没有输入字体名称两次在以下行project.ext.vectoricons = [ iconFontNames: [ 'FontAwesome.ttf','FontAwesome5_Brands.ttf','FontAwesome5_Regular.ttf','FontAwesome5_Solid.ttf',"Foundation.ttf","Ionicons.ttf","MaterialIcons.ttf","MaterialCommunityIcons.ttf","AntDesing.ttf","Entypo.ttf","EvilIcons.ttf","Feather.ttf","FontAwesome5.ttf","SimpleLineIcons.ttf","Octicons.ttf"] // Name of the font files you want to copy ]删除如果你有任何重复的名称条目为我工作

相关问题