Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

./gradlew build fails with implicit dependency errors #157

Open
pramod-knidal opened this issue Jun 27, 2023 · 4 comments
Open

./gradlew build fails with implicit dependency errors #157

pramod-knidal opened this issue Jun 27, 2023 · 4 comments

Comments

@pramod-knidal
Copy link

pramod-knidal commented Jun 27, 2023

🐛 Describe the bug

./gradlew build command fails with the following error

* What went wrong:
Some problems were found with the configuration of task 'app:ktfmtFormatMain' (type 'KtfmtFormatTask').
  - Gradle detected a problem with the following location: '<project-dir>/src/main/java'.
    
    Reason: Task 'app:ktfmtCheckMain' uses this output of task 'app:ktfmtFormatMain' 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 'app:ktfmtFormatMain' as an input of 'app:ktfmtCheckMain'.
      2. Declare an explicit dependency on 'app:ktfmtFormatMain' from 'app:ktfmtCheckMain' using Task#dependsOn.
      3. Declare an explicit dependency on 'app:ktfmtFormatMain' from 'app:ktfmtCheckMain' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '<project-dir>/src/main/kotlin'.
    
    Reason: Task 'app:ktfmtCheckMain' uses this output of task 'app:ktfmtFormatMain' 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 'app:ktfmtFormatMain' as an input of 'app:ktfmtCheckMain'.
      2. Declare an explicit dependency on 'app:ktfmtFormatMain' from 'app:ktfmtCheckMain' using Task#dependsOn.
      3. Declare an explicit dependency on 'app:ktfmtFormatMain' from 'app:ktfmtCheckMain' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.

⚠️ Current behavior

./gradlew build fails with error

✅ Expected behavior

./gradlew build should not throw any warnings/errors related to ktfmt-gradle plugin.

💣 Steps to reproduce

  1. Include ktfmt plugin 0.12.0 in an android library project id 'com.ncorti.ktfmt.gradle' version '0.12.0'
  2. run ./gradlew build from terminal

📱 Tech info

  • Device: Mac M1
  • OS: Mac 13.4
  • Library Version: 0.12.0
  • Gradle Version: 8.1.1

Notes

I found this issue when I was trying to generate a release build using 'maven-publish' which threw errors similar to the one above but it was asking me to include the implicit dependency between 'sourceReleaseJartask andktfmtFormatRelease`.

A workaround for now would be appreciated.

@WhosNickDoglio
Copy link

I think the error message is giving you a workaround? You need to make the relationship between tasks more explicit and could use dependsOn or mustRunAfter to do that.

Adding the following should work.

tasks.named("ktfmtCheckMain") {
    dependsOn("ktfmtFormatMain")
}

@pramod-knidal
Copy link
Author

I think the error message is giving you a workaround? You need to make the relationship between tasks more explicit and could use dependsOn or mustRunAfter to do that.

Adding the following should work.

tasks.named("ktfmtCheckMain") {
    dependsOn("ktfmtFormatMain")
}

Yeah. Tried several things similar to the one you noted. It was throwing an error saying ktfmtCheckMain task not found. In gradle, the ordering matters. So, tried putting that logic in several places until it worked. After it worked, there was another similar error saying sourcesReleaseJar should depend on ktfmtFormatMain. After I fixed that, there was another similar one.

I thought having these dependencies explicitly defined in the plugin code would be a good solution. So, posted an issue here.

@cortinico
Copy link
Owner

@pramodshri-tgsys Thanks for the report

I thought having these dependencies explicitly defined in the plugin code would be a good solution. So, posted an issue here.

The two tasks should not depend on each other. Could you provide a reproducer where you're having this behavior as I can't reproduce it in my testing?

@pramod-knidal
Copy link
Author

@cortinico I don't have a reproducer. It was happening in a proprietary project when I tried to publish an aar for an android library project using gradle plugin for maven publish. It happens only when you try to publish a release aar.

You note that the two tasks should not depend on each other. However, adding the code that @WhosNickDoglio has put in his comment will get you past the error... to a new error...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants