ankidroid / ankidroid/Anki-Android

Implicit gradle dependencies cause build errors for some tasks

未关闭
#13,277 10 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Blocked by dependency Dev Keep Open
主要语言
Kotlin
星标
11.8k
派生
2.9k
平均合并
2 天 3 小时
30 天内合并 PR
171

描述

Implicit dependencies cause build errors for some tasks

Strange one here - our CI is working because if you do this sequence (which our CI does as gradle warm then test) things work:

```bash
./gradlew packagePlayDebug packagePlayDebugAndroidTest --daemon
./gradlew uninstallAll jacocoAndroidTestReport --daemon
```

But if you do this:

```bash
./gradlew clean uninstallAll jacocoTestReport :api:lintRelease :AnkiDroid:lintPlayRelease ktlintCheck lint-rules:test
```

... there is some implicit dependency on the build dir used by the report and various tasks that drop things in the build dir, specifically:

```
* What went wrong:
Some problems were found with the configuration of task ':AnkiDroid:jacocoTestReport' (type 'JacocoReport').
- Gradle detected a problem with the following location: '/home/mike/work/AnkiDroid/Anki-Android-Upstream/AnkiDroid/build'.

Reason: Task ':AnkiDroid:jacocoTestReport' uses this output of task ':AnkiDroid:compilePlayReleaseAidl' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

Possible solutions:
1. Declare task ':AnkiDroid:compilePlayReleaseAidl' as an input of ':AnkiDroid:jacocoTestReport'.
2. Declare an explicit dependency on ':AnkiDroid:compilePlayReleaseAidl' from ':AnkiDroid:jacocoTestReport' using Task#dependsOn.
3. Declare an explicit dependency on ':AnkiDroid:compilePlayReleaseAidl' from ':AnkiDroid:jacocoTestReport' using Task#mustRunAfter.

Please refer to https://docs.gradle.org/8.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
- Gradle detected a problem with the following location: '/home/mike/work/AnkiDroid/Anki-Android-Upstream/AnkiDroid/build'.

Reason: Task ':AnkiDroid:jacocoTestReport' uses this output of task ':AnkiDroid:compilePlayReleaseJavaWithJavac' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

Possible solutions:
1. Declare task ':AnkiDroid:compilePlayReleaseJavaWithJavac' as an input of ':AnkiDroid:jacocoTestReport'.
2. Declare an explicit dependency on ':AnkiDroid:compilePlayReleaseJavaWithJavac' from ':AnkiDroid:jacocoTestReport' using Task#dependsOn.
3. Declare an explicit dependency on ':AnkiDroid:compilePlayReleaseJavaWithJavac' from ':AnkiDroid:jacocoTestReport' using Task#mustRunAfter.

Please refer to https://docs.gradle.org/8.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
- Gradle detected a problem with the following location: '/home/mike/work/AnkiDroid/Anki-Android-Upstream/AnkiDroid/build'.

Reason: Task ':AnkiDroid:jacocoTestReport' uses this output of task ':AnkiDroid:mergePlayReleaseResources' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

Possible solutions:
1. Declare task ':AnkiDroid:mergePlayReleaseResources' as an input of ':AnkiDroid:jacocoTestReport'.
2. Declare an explicit dependency on ':AnkiDroid:mergePlayReleaseResources' from ':AnkiDroid:jacocoTestReport' using Task#dependsOn.
3. Declare an explicit dependency on ':AnkiDroid:mergePlayReleaseResources' from ':AnkiDroid:jacocoTestReport' using Task#mustRunAfter.

Please refer to https://docs.gradle.org/8.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
- Gradle detected a problem with the following location: '/home/mike/work/AnkiDroid/Anki-Android-Upstream/AnkiDroid/build'.

Reason: Task ':AnkiDroid:jacocoTestReport' uses this output of task ':AnkiDroid:generatePlayReleaseResValues' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

Possible solutions:
1. Declare task ':AnkiDroid:generatePlayReleaseResValues' as an input of ':AnkiDroid:jacocoTestReport'.
2. Declare an explicit dependency on ':AnkiDroid:generatePlayReleaseResValues' from ':AnkiDroid:jacocoTestReport' using Task#dependsOn.
3. Declare an explicit dependency on ':AnkiDroid:generatePlayReleaseResValues' from ':AnkiDroid:jacocoTestReport' using Task#mustRunAfter.

Please refer to https://docs.gradle.org/8.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
- Gradle detected a problem with the following location: '/home/mike/work/AnkiDroid/Anki-Android-Upstream/AnkiDroid/build'.

Reason: Task ':AnkiDroid:jacocoTestReport' uses this output of task ':AnkiDroid:generatePlayReleaseBuildConfig' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

Possible solutions:
1. Declare task ':AnkiDroid:generatePlayReleaseBuildConfig' as an input of ':AnkiDroid:jacocoTestReport'.
2. Declare an explicit dependency on ':AnkiDroid:generatePlayReleaseBuildConfig' from ':AnkiDroid:jacocoTestReport' using Task#dependsOn.
3. Declare an explicit dependency on ':AnkiDroid:generatePlayReleaseBuildConfig' from ':AnkiDroid:jacocoTestReport' using Task#mustRunAfter.

Please refer to https://docs.gradle.org/8.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
```

I played around with it a bit and the "area" (vague statement, apologies) of the problem is related to task definition - that is, what tasks are generating what outputs where and what the test tasks actually depend on. The general idea in modern gradle is to define inputs / outputs explicitly on tasks vs depending on files and directories and things with `**/dirname` etc - and we could improve that a lot.

It is also possible that simply defining the task dependencies better for the jacoco test tasks could do it, for instance making it depend on assemblePlayDebug or similar, but then we run into problems with the APK signing configuration and need for passwords etc.

So the correct fix is likely to alter the report tasks such that it really only depends on the actual outputs it needs somehow, using gradle Providers vs raw dirs and files, but I'm not sure exactly how to do it best - so that's the task

_Originally posted by @mikehardy in https://github.com/ankidroid/Anki-Android/issues/13269#issuecomment-1433282848_

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。