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

Upgrade from 1.14.2 to 1.15.1 causes "Caused by: java.lang.NoSuchMethodError: 'java.io.File com.squareup.kotlinpoet.FileSpec.writeTo(java.io.File)'" #1730

Closed
ebraminio opened this issue Nov 20, 2023 · 4 comments
Labels

Comments

@ebraminio
Copy link

ebraminio commented Nov 20, 2023

Describe the bug
Apparently an upgrade from 1.14.2 to 1.15.1 causes "Caused by: java.lang.NoSuchMethodError: 'java.io.File com.squareup.kotlinpoet.FileSpec.writeTo(java.io.File)'" as can be seen in https://github.com/persian-calendar/persian-calendar/actions/runs/6924586914/job/18834021299#step:6:70

To Reproduce
Build before and after this change proposed by dependabot persian-calendar/persian-calendar#1192 it's not a big project and doesn't have a network access so should be safe to build but I'll understand if you want a separate minimal project to reproduce the issue (while I believe this project isn't a hairy one also). It's weird just this change can cause a build failure without any indication on the solution.

Expected behavior
To work as before I think.

Additional context
Before filing this bug I saw #1476 which indicated something similar can happen because of ksp, while we also have an updated ksp but it isn't used yet for some reason so I even disabled it with no difference. Just to note that project has kotlin = "1.9.20" and ksp = "1.9.20-1.0.14", exactly as mentioned by KotlinPoet's 1.15.1 release note also.

I usually don't file such kind of reports and usually will try to resolve issues myself even on other projects but this felt weird so thought probably I can get some help, but I'll understand if you don't like it. Thanks

@lukellmann
Copy link

The exception names the newly added method in 1.5.0/1.5.1 (it returns java.io.File) as missing, so it seems like you compile against the new KotlinPoet version while running with an older version that doesn't have the new method.

@ebraminio
Copy link
Author

ebraminio commented Nov 20, 2023

Makes sense. Probably the project has some dependency that pulls its own version of KotlinPoet? Even if so that dependency should be a very fundamental one I think as the project doesn't have not well known third party dependencies. Here is the project's KotlinPoet build mentions.

image

@JakeWharton
Copy link
Collaborator

Your plugin is only applied in the child :PersianCalendar project whereas the Safe Args navigation plugin is setup in the root project. Thus, its dependency on KotlinPoet wins because your plugin's dependencies do not get participate in resolution semantics. Remember, 100% of the plugins you use need to be specified in the root with apply false or else you'll get incredibly cryptic behavior.

Apply this change:

diff --git PersianCalendar/build.gradle.kts PersianCalendar/build.gradle.kts
index 28f065a01..108388c5d 100644
--- PersianCalendar/build.gradle.kts
+++ PersianCalendar/build.gradle.kts
@@ -9,7 +9,7 @@ plugins {
     alias(libs.plugins.kotlin.android)
     alias(libs.plugins.androidx.navigation.safeargs.kotlin)
     alias(libs.plugins.ksp)
-    id("io.github.persiancalendar.appbuildplugin") apply true
+    id("io.github.persiancalendar.appbuildplugin")
 }

 val generatedAppSrcDir =
diff --git build.gradle.kts build.gradle.kts
index d0f79c9c5..8e2d45472 100644
--- build.gradle.kts
+++ build.gradle.kts
@@ -3,6 +3,7 @@ plugins {
     alias(libs.plugins.kotlin.android) apply false
     alias(libs.plugins.androidx.navigation.safeargs.kotlin) apply false
     alias(libs.plugins.ksp) apply false
+    id("io.github.persiancalendar.appbuildplugin") apply false
 }

 task("clean") {

You can verify the behavior change using the buildEnvironment task.

Before:

+--- androidx.navigation.safeargs.kotlin:androidx.navigation.safeargs.kotlin.gradle.plugin:2.7.5
|    \--- androidx.navigation:navigation-safe-args-gradle-plugin:2.7.5
|         +--- androidx.navigation:navigation-safe-args-generator:2.7.5
|         |    +--- com.squareup:javapoet:1.13.0
|         |    +--- com.squareup:kotlinpoet:1.14.2

After:

+--- androidx.navigation.safeargs.kotlin:androidx.navigation.safeargs.kotlin.gradle.plugin:2.7.5
|    \--- androidx.navigation:navigation-safe-args-gradle-plugin:2.7.5
|         +--- androidx.navigation:navigation-safe-args-generator:2.7.5
|         |    +--- com.squareup:javapoet:1.13.0
|         |    +--- com.squareup:kotlinpoet:1.14.2 -> 1.15.1

...

+--- project :gradlePlugins
|    +--- com.squareup:kotlinpoet:1.15.1 (*)

@JakeWharton JakeWharton closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2023
ebraminio pushed a commit to persian-calendar/persian-calendar that referenced this issue Nov 20, 2023
@ebraminio
Copy link
Author

ebraminio commented Nov 20, 2023

Thank you so much for the help and sorry for the plugin misconfiguration 🙏 Feel free to have a look at the app also, might have interesting things, it's a more or less popular fully offline non-profit and free local app 😊

ebraminio added a commit to persian-calendar/persian-calendar that referenced this issue Nov 20, 2023
As square/kotlinpoet#1730 (comment)

  "Remember, 100% of the plugins you use need to be specified in the root with apply false or else you'll get incredibly cryptic behavior."
HrBDev pushed a commit to persian-calendar/persian-calendar that referenced this issue Apr 6, 2024
HrBDev pushed a commit to persian-calendar/persian-calendar that referenced this issue Apr 6, 2024
As square/kotlinpoet#1730 (comment)

  "Remember, 100% of the plugins you use need to be specified in the root with apply false or else you'll get incredibly cryptic behavior."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants