gradle 如何在应用插件中集成重复处理策略

vql8enpb  于 2023-02-09  发布在  其他
关注(0)|答案(2)|浏览(268)

我正在我的一个项目中使用应用程序插件。升级到Gradle 7.x后,我遇到了故障:

Execution failed for task ':xyz:distTar'.
        > Entry xyz-1.0/lib/jaxb-core-3.0.1.jar is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.3.3/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.

我发现了一个堆栈溢出的帖子与Gradle 7 task ':distTar' is a duplicate but no duplicate...有关。但是合并的建议...

tasks.withType<Tar> {
   duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

tasks.withType<Zip>{
   duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

没有成功。它以失败告终。

A problem occurred evaluating project ':integration-test'.
> Could not get unknown property 'withType' for task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.

我的build. gradle看起来基本上是这样的...

apply plugin: 'java'
apply plugin: 'application'

version = '1.0'
sourceCompatibility = 11
targetCompatibility = 11

repositories {
    mavenCentral()
}

dependencies {
    implementation(
        ...
    )
}

application {
    mainClassName = 'a.b.c.XYZ'
}

你知道吗?

dw1jzc5e

dw1jzc5e1#

那不是应该加上正规的括号吗?

tasks.withType(Tar) {
   duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

或:

tasks.withType(Tar.class).configureEach {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
qxsslcnc

qxsslcnc2#

请注意,如果您在应用程序插件中使用installDist任务(而不是distTar),则需要设置:

installDist {
    ...
    duplicatesStrategy = DuplicatesStrategy.INCLUDE

    ...
}

相关问题