spring 无法添加gradle重复项策略固有

fcwjkofz  于 2023-01-04  发布在  Spring
关注(0)|答案(1)|浏览(319)

在我的gradle 7.5.1项目中,以下任务出现错误

processResources {
    with copySpec {
        from "src/main/resources/"
    }
}

这是错误信息。我的资源文件夹中有application.propertiesapplication-dev.propertiesapplication-test.properties文件。

Entry application-dev.properties is a duplicate but no duplicate handling strategy has been set.

所以我试着添加像贝娄这样的复制策略

allprojects {
    tasks.withType(Copy).all {
        duplicatesStrategy = DuplicatesStrategy.INCLUDE
    }
}

在添加此之后,项目运行,但现在我需要另一个策略INHERIT。如果我用DuplicatesStrategy.INHERIT替换DuplicatesStrategy.INCLUDE,我会再次得到相同的错误

Entry application-dev.properties is a duplicate but no duplicate handling strategy has been set

我检查了(参见实现)DuplicatesStrategy枚举,INHERIT是一个有效值。

package org.gradle.api.file;

public enum DuplicatesStrategy {
    INCLUDE,
    EXCLUDE,
    WARN,
    FAIL,
    INHERIT;

    private DuplicatesStrategy() {
    }
}

如何正确添加重复策略?

bnl4lu3b

bnl4lu3b1#

由于我找不到问题所在,我决定采用相同的策略INCLUDEDuplicate Strategy具有以下文档

EXCLUDE Do not allow duplicates by ignoring subsequent items to be created at the same path.
FAIL    Throw a DuplicateFileCopyingException when subsequent items are to be created at the same path.
INCLUDE Do not attempt to prevent duplicates.
INHERIT The default strategy, which is to inherit the strategy from the parent copy spec, if any, or INCLUDE if the copy spec has no parent.
WARN    Do not attempt to prevent duplicates, but log a warning message when multiple items are to be created at the same path.

由于我的copySpec没有任何父项,我希望INCLUDE会被自动使用。但由于它没有发生,我决定使用INCLUDE而不是INHERIT

相关问题