Anki-Android icon indicating copy to clipboard operation
Anki-Android copied to clipboard

Implicit gradle dependencies cause build errors for some tasks

Open mikehardy opened this issue 1 year ago • 6 comments

          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:

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

But if you do this:

./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

mikehardy avatar Feb 16 '23 15:02 mikehardy