从 Gradle 输出中删除隐式依赖警告

2024-01-04

我的 Gradle 构建中有一个通用任务,它复制一些配置文件以包含在构建中,但编译或其他任何操作都不需要这些文件(它们在运行时使用)。基本上:

val copyConfiguration by tasks.registering(Copy::class) {
    from("${projectDir}/configuration")
    into("${buildDir}/")
}

然而,这会导致所有其他任务中出现问题,因为我现在收到有关任务如何使用此输出而不声明显式或隐式依赖项的 Gradle 警告

Execution optimizations have been disabled for task ':jacocoTestCoverageVerification' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '...'. Reason: Task ':jacocoTestCoverageVerification' uses this output of task ':copyConfiguration' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.4.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.

现在这只是一个警告,构建成功,我的服务启动并运行良好。但它确实阻塞了我的输出,使我更难找到出现问题的行,并且通常是碍眼的。我想以某种方式删除该警告。我(从 wiki)看到,一般的解决方案是在任务定义中编写显式依赖项,但由于每个任务都会发生这种情况(从编译、测试、ktlint、jacoco 等),我不知道真的不想那么做。

是否有其他选择,例如反依赖,我可以告诉 Gradle 它不应该关心:copyConfiguration task?


鉴于(强调我的以显示要寻找的内容)

由于以下原因,已禁用任务“spotlessJava”的执行优化以确保正确性:

  • Gradle 检测到以下位置存在问题:“...\build\ generated\source\proto\main\grpc”。原因:任务'一尘不染的Java'使用此任务的输出'生成原型'无需声明显式或隐式依赖关系。这可能会导致产生不正确的结果,具体取决于任务的执行顺序。请参阅https://docs.gradle.org/7.5.1/userguide/validation_problems.html#implicit_dependency https://docs.gradle.org/7.5.1/userguide/validation_problems.html#implicit_dependency有关此问题的更多详细信息。

将以下内容添加到build.gradle

tasks.named("spotlessJava").configure { dependsOn("generateProto") }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 Gradle 输出中删除隐式依赖警告 的相关文章

随机推荐