dependency-analysis-gradle-plugin: NoSuchMethodError: kotlinx.metadata.jvm.KotlinClassHeader.

Build scan link Unfortunately, due to security restrictions I am not allowed to run build scans on the project with which I can reproduce the issue. I’ve yet to reproduce it with a minimal test project.

Plugin version 0.77.0 - 1.5.0

Gradle version 7.4.2

(Optional) Android Gradle Plugin (AGP) version N/A, server-side JVM app.

Describe the bug

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':myproject:graphViewMain'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:147)
[...]
Caused by: java.lang.NoSuchMethodError: 'void kotlinx.metadata.jvm.KotlinClassHeader.<init>(java.lang.Integer, int[], java.lang.String[], java.lang.String[], java.lang.String, java.lang.String, java.lang.Integer)'
	at dev.zacsweers.moshix.sealed.reflect.MetadataMoshiSealedJsonAdapterFactoryKt.header(MetadataMoshiSealedJsonAdapterFactory.kt:153)
	at dev.zacsweers.moshix.sealed.reflect.MetadataMoshiSealedJsonAdapterFactoryKt.access$header(MetadataMoshiSealedJsonAdapterFactory.kt:1)
	at dev.zacsweers.moshix.sealed.reflect.MetadataMoshiSealedJsonAdapterFactory.create(MetadataMoshiSealedJsonAdapterFactory.kt:57)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:145)
	at com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory.create(KotlinJsonAdapter.kt:262)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:145)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:105)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:74)
	at com.squareup.moshi.CollectionJsonAdapter.newLinkedHashSetAdapter(CollectionJsonAdapter.java:65)
	at com.squareup.moshi.CollectionJsonAdapter$1.create(CollectionJsonAdapter.java:40)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:145)
	at com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory.create(KotlinJsonAdapter.kt:262)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:145)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:105)
	at com.squareup.moshi.AdapterMethodsFactory$3.bind(AdapterMethodsFactory.java:214)
	at com.squareup.moshi.AdapterMethodsFactory.create(AdapterMethodsFactory.java:67)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:145)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:105)
	at com.squareup.moshi.Moshi.adapter(Moshi.java:79)
	at com.autonomousapps.tasks.GraphViewTask.action(GraphViewTask.kt:191)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[...]

To Reproduce Steps to reproduce the behavior:

  1. .\gradlew buildHealth

Expected behavior An insanely great dependency analysis report.

Additional context

.\gradlew buildEnvironment

classpath
+--- com.autonomousapps.dependency-analysis:com.autonomousapps.dependency-analysis.gradle.plugin:1.2.0
|    \--- com.autonomousapps:dependency-analysis-gradle-plugin:1.2.0
|         +--- org.jetbrains.kotlin:kotlin-bom:1.5.31
|         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.5.31
|         |    |    +--- org.jetbrains:annotations:13.0
|         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31
|         |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.5.31 (*)
|         +--- com.squareup.moshi:moshi:1.12.0
|         |    +--- com.squareup.okio:okio:2.10.0
|         |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.20 -> 1.5.31 (*)
|         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.20 -> 1.5.31
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 -> 1.5.31 (*)
|         +--- com.squareup.moshi:moshi-kotlin:1.12.0
|         |    +--- com.squareup.moshi:moshi:1.12.0 (*)
|         |    +--- org.jetbrains.kotlin:kotlin-reflect:1.4.31 -> 1.5.31
|         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.5.31 (*)
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 -> 1.5.31 (*)
|         +--- com.squareup.moshi:moshi-adapters:1.12.0
|         |    +--- com.squareup.moshi:moshi:1.12.0 (*)
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 -> 1.5.31 (*)
|         +--- dev.zacsweers.moshix:moshi-sealed-runtime:0.14.1
|         |    +--- com.squareup.moshi:moshi-adapters:1.12.0 (*)
|         |    +--- com.squareup.moshi:moshi:1.12.0 (*)
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30 -> 1.5.31 (*)
|         +--- dev.zacsweers.moshix:moshi-sealed-metadata-reflect:0.14.1
|         |    +--- dev.zacsweers.moshix:moshi-sealed-runtime:0.14.1 (*)
|         |    +--- org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0
|         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.5.0 -> 1.5.31 (*)
|         |    +--- com.squareup.moshi:moshi:1.12.0 (*)
|         |    +--- com.squareup.moshi:moshi-adapters:1.12.0 (*)
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30 -> 1.5.31 (*)
|         +--- org.jetbrains.kotlin:kotlin-reflect:1.5.31 (*)
|         +--- org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0 (*)
|         +--- com.github.ben-manes.caffeine:caffeine:3.0.4
|         |    +--- org.checkerframework:checker-qual:3.18.0
|         |    \--- com.google.errorprone:error_prone_annotations:2.9.0
|         \--- com.google.guava:guava:31.0.1-jre
|              +--- com.google.guava:failureaccess:1.0.1
|              +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|              +--- com.google.code.findbugs:jsr305:3.0.2
|              +--- org.checkerframework:checker-qual:3.12.0 -> 3.18.0
|              +--- com.google.errorprone:error_prone_annotations:2.7.1 -> 2.9.0
|              \--- com.google.j2objc:j2objc-annotations:1.3
.\gradlew --version

------------------------------------------------------------         
Gradle 7.4.2                                                         
------------------------------------------------------------         
                                                                     
Build time:   2022-03-31 15:25:29 UTC                                
Revision:     540473b8118064efcc264694cbcaa4b677f61041               
                                                                     
Kotlin:       1.5.31                                                 
Groovy:       3.0.9                                                  
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.15 (Eclipse Adoptium 11.0.15+10)                  
OS:           Windows 10 10.0 amd64

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (9 by maintainers)

Commits related to this issue

Most upvoted comments

The only thing the plugin could do is to shade more dependencies to avoid classpath conflicts. That can really bloat plugin size though, so I’m hesitant to do that.

This is the only time this has come up, so I’m not sure it qualifies as a “frequently” asked question 😅 But if you propose some text for the FAQ section of the wiki, I would be willing to add it. (Unfortunately, it is impossible to have PRs for the github wiki 🤷 )

There it is! buildSrc overrides everything else thanks to how classpaths work on the JVM. (Parent classloader wins, buildSrc is the parent.)

Our case: In buildSrc/build.gradle we add some plugin to classpath in dependencies block to compile some old stuff. This plugin uses org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.1.0.

Just applying com.autonomousapps.dependency-analysis in root build.gradle is not working because of error in this issue. But when we:

  • remove the plugin from buildSrc classpath

or

  • add com.autonomousapps.dependency-analysis:com.autonomousapps.dependency-analysis.gradle.plugin:1.7.0 to buildSrc classpath

then the error disappears.

Very sorry, I missed your comment that 1.2.1 didn’t resolve your issue. I note that the stacktrace is different than what you originally opened the issue with, so apparently we’ve just pushed the problem elsewhere by removing the Moshi dependency.

Let’s reopen this issue. I’ll get back to you with potential debugging steps.

1.2.1 does work with my smaller test project, so no additional insights there I’m afraid: https://github.com/sdkotlin/sd-kotlin-talks/tree/d8a1dfd1ef546acbe01c585838471577f15884d4.

This will be released as 1.2.1.