JetBrains / intellij-platform-gradle-plugin

Gradle plugin for building plugins for JetBrains IDEs
https://plugins.jetbrains.com/docs/intellij/gradle-prerequisites.html
Apache License 2.0
1.44k stars 272 forks source link

publishPlugin fails with NoSuchFieldError: Companion #530

Closed sewe closed 1 year ago

sewe commented 4 years ago

Using the org.jetbrains.intellij, version 0.4.22, running on Java 8, we get a NoSuchFieldError: Companion.

Running the publishPlugin task

./gradlew :intellij:com.teamscale.ide.intellij:publishPlugin -PdeployUsername=… -PdeployToken=… -PzipFile=…

with

publishPlugin {
        if (project.hasProperty("deployUsername") && project.hasProperty("deployToken") && project.hasProperty("zipFile")) {
                username deployUsername
                token deployToken
                distributionFile zipFile
        }
}

results in the following exception.

Caused by: java.lang.NoSuchFieldError: Companion
    at org.jetbrains.intellij.pluginRepository.internal.utils.RequestHelperKt.toMultipartBody(RequestHelper.kt:96)
    at org.jetbrains.intellij.pluginRepository.internal.instances.PluginUploaderInstance.uploadPluginInternal(PluginUploaderInstance.kt:45)
    at org.jetbrains.intellij.pluginRepository.internal.instances.PluginUploaderInstance.uploadPluginInternal$default(PluginUploaderInstance.kt:38)
    at org.jetbrains.intellij.pluginRepository.internal.instances.PluginUploaderInstance.uploadPlugin(PluginUploaderInstance.kt:30)
    at org.jetbrains.intellij.pluginRepository.PluginUploader$uploadPlugin.call(Unknown Source)
    at org.jetbrains.intellij.tasks.PublishTask.publishPlugin(PublishTask.groovy:129)

AFAICT, this seems to be related to OkHttp. And indeed there is a suspicious version mismatch (com.squareup.okhttp3:okhttp 3.14.4 -> 4.3.1) on the build classpath:

$ ./gradlew :intellij:buildEnvironment

> Task :intellij:buildEnvironment

------------------------------------------------------------
Project :intellij
------------------------------------------------------------

classpath
\--- org.jetbrains.intellij:org.jetbrains.intellij.gradle.plugin:0.4.22
     \--- gradle.plugin.org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.4.22
          +--- org.jetbrains:annotations:19.0.0
          +--- org.jetbrains.intellij.plugins:structure-base:3.105
          |    +--- org.jetbrains:annotations:13.0 -> 19.0.0
          |    +--- org.slf4j:slf4j-api:1.7.21 -> 1.7.26
          |    +--- commons-io:commons-io:2.6
          |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.70
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.70
          |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.70
          |    |    |    \--- org.jetbrains:annotations:13.0 -> 19.0.0
          |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.70
          |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.70 (*)
          |    +--- org.apache.commons:commons-compress:1.20
          |    +--- org.tukaani:xz:1.6
          |    \--- org.atteo:evo-inflector:1.2.2
          +--- org.jetbrains.intellij.plugins:structure-intellij:3.105
          |    +--- org.glassfish.jaxb:jaxb-runtime:2.3.1
          |    |    +--- javax.xml.bind:jaxb-api:2.3.1
          |    |    |    \--- javax.activation:javax.activation-api:1.2.0
          |    |    +--- org.glassfish.jaxb:txw2:2.3.1
          |    |    +--- com.sun.istack:istack-commons-runtime:3.0.7
          |    |    +--- org.jvnet.staxex:stax-ex:1.8
          |    |    +--- com.sun.xml.fastinfoset:FastInfoset:1.2.15
          |    |    \--- javax.activation:javax.activation-api:1.2.0
          |    +--- org.jetbrains.intellij.plugins:structure-base:3.105 (*)
          |    +--- org.jdom:jdom:2.0.2
          |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.70 (*)
          |    +--- org.jsoup:jsoup:1.9.2
          |    +--- org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.70 (*)
          |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.70
          |    \--- javax.xml.bind:jaxb-api:2.3.1 (*)
          +--- org.jetbrains.intellij:plugin-repository-rest-client:2.0.6
          |    +--- org.slf4j:slf4j-api:1.7.26
          |    +--- com.squareup.retrofit2:retrofit:2.7.0
          |    |    \--- com.squareup.okhttp3:okhttp:3.14.4 -> 4.3.1
          |    |         \--- com.squareup.okio:okio:2.4.1
          |    +--- com.squareup.retrofit2:converter-jaxb:2.7.0
          |    |    +--- com.squareup.retrofit2:retrofit:2.7.0 (*)
          |    |    \--- javax.xml.bind:jaxb-api:2.3.1 (*)
          |    +--- com.squareup.retrofit2:converter-jackson:2.7.0
          |    |    +--- com.squareup.retrofit2:retrofit:2.7.0 (*)
          |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.9.10.1 -> 2.10.1
          |    |         +--- com.fasterxml.jackson.core:jackson-annotations:2.10.1
          |    |         \--- com.fasterxml.jackson.core:jackson-core:2.10.1
          |    +--- com.squareup.okhttp3:okhttp:4.3.1 (*)
          |    +--- com.fasterxml.jackson.module:jackson-module-kotlin:2.10.1
          |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.10.1 (*)
          |    |    \--- com.fasterxml.jackson.core:jackson-annotations:2.10.1
          |    +--- com.sun.xml.bind:jaxb-impl:2.3.2
          |    \--- com.sun.xml.bind:jaxb-core:2.3.0
          \--- de.undercouch:gradle-download-task:4.0.4

(*) - dependencies omitted (listed previously)

Is this a known issue? And are there any workarounds?

(NB: We use publishPlugin with explicitly set distributionFile in a separate Gradle invocation since the actual plug-in ZIP is already build and tested in an earlier step of a lengthy pipeline.)

YannCebron commented 4 years ago

related? #522

sewe commented 4 years ago

related? #522

Might be. As to your question in #522:

Any chance to upgrade to more recent Gradle 6.x?

The above NoSuchFieldError occurs with the following:

$ ./gradlew --version

------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------

Build time:   2019-11-18 20:25:01 UTC
Revision:     fad121066a68c4701acd362daf4287a7c309a0f5

Kotlin:       1.3.50
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_252 (Private Build 25.252-b09)
OS:           Linux 4.15.0-117-generic amd64

Hope this helps.

sewe commented 4 years ago

FWIW, with the latest Gradle 6.6.1 the above buildEnvironment tree looks exactly the same.

sewe commented 4 years ago

More input (using git bisect run). The likely problem, i.e., the okhttp version mismatch (as found by ./gradlew :intellij:buildEnvironment | grep 'okhttp.*->'), was introduced when we updated from org.jetbrains.intellij version 0.4.15 to 0.4.21 to consume the fix for #123.

sewe commented 4 years ago

A bit more (manual) bisecting shows that the version mismatch was introduced between org.jetbrains.intellij version 0.4.16 to 0.4.17. Hope that helps.

sewe commented 4 years ago

Can someone else please verify that their buildEnvironment also contains the suspicious com.squareup.okhttp3:okhttp:3.14.4 -> 4.3.1 upgrade? Would like to ascertain that this is not some weird side-effect of our build (which is unfortunately not public).

zolotov commented 4 years ago

Can someone else please verify that their buildEnvironment also contains the suspicious com.squareup.okhttp3:okhttp:3.14.4 -> 4.3.1 upgrade?

It does contain for me. Still publishing seems to work. Could you try 0.5-SNAPSHOT? It has newer plugin uploading library. See the instructions here: https://github.com/JetBrains/gradle-intellij-plugin#snapshot-version

YannCebron commented 4 years ago

can you reproduce with 0.5 release?

sewe commented 4 years ago

@YannCebron I am afraid I can reproduce with 0.5. Here’s the stacktrace:

Execution failed for task ':intellij:com.teamscale.ide.intellij:publishPlugin'.
> Companion
* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':intellij:com.teamscale.ide.intellij:publishPlugin'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:187)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:185)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:166)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:374)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:361)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:354)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:340)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: java.lang.NoSuchFieldError: Companion
    at org.jetbrains.intellij.pluginRepository.internal.utils.RequestHelperKt.toMultipartBody(RequestHelper.kt:96)
    at org.jetbrains.intellij.pluginRepository.internal.instances.PluginUploaderInstance.uploadPluginInternal(PluginUploaderInstance.kt:45)
    at org.jetbrains.intellij.pluginRepository.internal.instances.PluginUploaderInstance.uploadPluginInternal$default(PluginUploaderInstance.kt:38)
    at org.jetbrains.intellij.pluginRepository.internal.instances.PluginUploaderInstance.uploadPlugin(PluginUploaderInstance.kt:30)
    at org.jetbrains.intellij.pluginRepository.PluginUploader$uploadPlugin.call(Unknown Source)
    at org.jetbrains.intellij.tasks.PublishTask.publishPlugin(PublishTask.groovy:129)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:49)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:42)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:721)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:688)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.run(ExecuteActionsTaskExecuter.java:539)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:524)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:507)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$300(ExecuteActionsTaskExecuter.java:109)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.executeWithPreviousOutputFiles(ExecuteActionsTaskExecuter.java:258)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:247)
    at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$1(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:63)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:49)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:34)
    at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:43)
    at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
    at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
    at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:34)
    at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:44)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:54)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:38)
    at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:153)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:67)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:41)
    at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
    at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:44)
    at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:33)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:92)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:85)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:55)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:39)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:76)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:94)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:49)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:79)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:53)
    at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:74)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:78)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:78)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:39)

We had to downgrade to 0.4.16 again to get our plug-in published.

hsz commented 4 years ago

That looks exactly like https://github.com/square/okhttp/issues/5818#issuecomment-625987434. Maybe it'd be necessary to simply shadow okhttp library in the JetBrains/plugin-repository-rest-client project?

cc @serejke

sewe commented 4 years ago

Very likely, as even the latest version of Retrofit2 (com.squareup.retrofit2:retrofit:2.9.0) still uses a 3.x of okhttp3, so the 3.x/4.x clash can't be fixed by simply updating plugin-repository-rest-client’s dependencies:

          +--- org.jetbrains.intellij:plugin-repository-rest-client:2.0.15
          |    +--- org.slf4j:slf4j-api:1.7.26
          |    +--- com.squareup.retrofit2:retrofit:2.7.0
          |    |    \--- com.squareup.okhttp3:okhttp:3.14.4 -> 4.3.1
          |    |         \--- com.squareup.okio:okio:2.4.1
          |    +--- com.squareup.retrofit2:converter-jaxb:2.7.0
          |    |    +--- com.squareup.retrofit2:retrofit:2.7.0 (*)
          |    |    \--- javax.xml.bind:jaxb-api:2.3.1 (*)
          |    +--- com.squareup.retrofit2:converter-jackson:2.7.0
          |    |    +--- com.squareup.retrofit2:retrofit:2.7.0 (*)
          |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.9.10.1 -> 2.11.0 (*)
          |    +--- com.squareup.okhttp3:okhttp:4.3.1 (*)
          |    +--- com.fasterxml.jackson.module:jackson-module-kotlin:2.10.1 -> 2.11.0 (*)
          |    +--- com.sun.xml.bind:jaxb-impl:2.3.2
          |    +--- com.sun.xml.bind:jaxb-core:2.3.0
          |    \--- org.jetbrains.intellij:blockmap:1.0.5
sewe commented 3 years ago

Just tested with 0.7.2. This is unfortunately still any issue, which means I am still stuck using 0.4.21, which is a real pity as I would very much like to use the runPluginVerifier task introduced in 0.6.

For the record, as https://github.com/JetBrains/gradle-intellij-plugin/issues/522 hints at this being specific to older Gradle versions, I have tried this with both Gradle 6.6.1 and 6.8.3 (as of this writing, the latest Gradle version). In either case, the problem persists.