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

Bra*_*ray 12 gradle

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

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

然而,这会导致所有其他任务中出现问题,因为我现在收到有关任务如何使用此输出而不声明显式或隐式依赖项的 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.
Run Code Online (Sandbox Code Playgroud)

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

是否有其他选择,例如反依赖,我可以告诉 Gradle 它不应该关心任务的输出:copyConfiguration

Arc*_*ano 11

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

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

添加以下内容到build.gradle

tasks.named("spotlessJava").configure { dependsOn("generateProto") }
Run Code Online (Sandbox Code Playgroud)


Ala*_*seh 2

我有一个类似的问题,有趣的是它始于与 Jacoco 相关的任务。我在这里记录了一个解决方案https://discuss.gradle.org/t/task-a-uses-this-output-of-task-b-without-declaring-an-explicit-or-implicit-dependency/42896

简而言之,对我有用的是使用任务属性(例如 getOutputs)获取问题所在的位置。希望这可以帮助。