ktlint-gradle icon indicating copy to clipboard operation
ktlint-gradle copied to clipboard

Update to Gradle 8.0 and Java 17

Open andrea157 opened this issue 2 years ago • 5 comments

After updating Android Studio to Flamingo | 2022.2.1, upgrading AGP to 8.0 and moving from Java 11 to Java 17 I started having problems; I have errors about the dependency of task addKtlintCheckGitPreCommitHook to other tasks.

Adding tasks.getByName("addKtlintCheckGitPreCommitHook") dependsOn(":app:createDebugVariantModel") the build now works but the tests keep failing; every run reports dependencies to tasks of other modules and even if I add them as dependencies every run there is always another task that gives errors like this

Some problems were found with the configuration of task ':addKtlintCheckGitPreCommitHook' (type 'KtlintInstallGitHookTask').
  - Gradle detected a problem with the following location: '.../AndroidStudioProjects/App/app'.
    
    Reason: Task ':addKtlintCheckGitPreCommitHook' uses this output of task ':module-name:...' 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 ':module-name:...' as an input of ':addKtlintCheckGitPreCommitHook'.
      2. Declare an explicit dependency on ':module-name:...' from ':addKtlintCheckGitPreCommitHook' using Task#dependsOn.
      3. Declare an explicit dependency on ':module-name:...' from ':addKtlintCheckGitPreCommitHook' using Task#mustRunAfter.

Any suggestions? Thanks

andrea157 avatar Apr 28 '23 14:04 andrea157

I have the same issue, not on the PreCommitHook but on the test sourcesets, also since updating to gradle 8.0, java 17 and kotlin 1.8.20 (not sure which caused the issues)

The errors I get are both on ktlintCheck and ktlintFormat:

  - Gradle detected a problem with the following location: '<projectdir>/build/generated/ksp/android/androidUnitTestDebug/kotlin'.
    
    Reason: Task ':<module>:runKtlintCheckOverCommonTestSourceSet' uses this output of task ':<module>:kspDebugUnitTestKotlinAndroid' 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 ':<module>:kspDebugUnitTestKotlinAndroid' as an input of ':<module>:runKtlintCheckOverCommonTestSourceSet'.
      2. Declare an explicit dependency on ':<module>:kspDebugUnitTestKotlinAndroid' from ':<module>:runKtlintCheckOverCommonTestSourceSet' using Task#dependsOn.
      3. Declare an explicit dependency on ':<module>:kspDebugUnitTestKotlinAndroid' from ':<module>:runKtlintCheckOverCommonTestSourceSet' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
- Gradle detected a problem with the following location: '<projectdir>/build/generated/ksp/android/androidUnitTestDebug/kotlin'.
    
    Reason: Task ':<module>:runKtlintFormatOverCommonTestSourceSet' uses this output of task ':<module>:kspDebugUnitTestKotlinAndroid' 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 ':common:mag-core:kspDebugUnitTestKotlinAndroid' as an input of ':<module>:runKtlintFormatOverCommonTestSourceSet'.
      2. Declare an explicit dependency on ':<module>:kspDebugUnitTestKotlinAndroid' from ':<module>:runKtlintFormatOverCommonTestSourceSet' using Task#dependsOn.
      3. Declare an explicit dependency on ':<module>:kspDebugUnitTestKotlinAndroid' from ':<module>:runKtlintFormatOverCommonTestSourceSet' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.

Same workaround works for me as well:

tasks.getByName("runKtlintCheckOverCommonTestSourceSet").dependsOn("kspDebugUnitTestKotlinAndroid")
tasks.getByName("runKtlintFormatOverCommonTestSourceSet").dependsOn("kspDebugUnitTestKotlinAndroid")

HylkeB avatar May 11 '23 12:05 HylkeB

Yes I tried to add the dependency like you but every time it reports a dependency to another task, I've added up to 20 dependencies, but still each build requires another new task 🥲

andrea157 avatar May 15 '23 07:05 andrea157

Also suffering from this issue. The app has 30 modules and every time I add one dependency it asks for more and more, would take hours to add everything as dependency. Any workaround for this one?

Tgo1014 avatar Aug 23 '23 10:08 Tgo1014

Any updates on this issue or workarounds?

kartikprakash1 avatar Oct 23 '23 22:10 kartikprakash1

Not at this time. Happy to accept a pull request that addresses these problems as long as an associated unit test is included 🙂

JLLeitschuh avatar Oct 31 '23 19:10 JLLeitschuh