Reason: Task ':xx:copyAar' uses this output of task ':xxx:bundleReleaseAar' with

35 阅读1分钟
* What went wrong:
A problem was found with the configuration of task ':rtk-support:bundleReleaseAar' (type 'BundleAar').
  - Gradle detected a problem with the following location: 'xxx.aar'.

    Reason: Task ':xx:copyAar' uses this output of task ':xxx:bundleReleaseAar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order th
e tasks are executed.

    Possible solutions:
      1. Declare task ':xxx:bundleReleaseAar' as an input of ':xxx:copyAar'.
      2. Declare an explicit dependency on ':xxx:bundleReleaseAar' from ':xxx:copyAar' using Task#dependsOn.
      3. Declare an explicit dependency on ':xxx:bundleReleaseAar' from ':xxx:copyAar' using Task#mustRunAfter.

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

原来的写法是这样子的的:

task Task1(type: Copy) {
    from xx
    into xx
    doLast {
        xx
    }
}
task Task2(type: Copy) {
    from xx
    into xx
    doLast {
        xx
    }
}
Task2.dependsOn(Task1)

改成下面这种写法即可:

task Task1(type: Copy) {
    dependsOn(build)
    
    from xx
    into xx
    doLast {
        xx
    }
}
task Task2(type: Copy) {
    dependsOn(Task1)
    
    from xx
    into xx
    doLast {
        xx
    }
}