Ktlint: Kotlin 1.4.0 Compatibility

Created on 14 Aug 2020  路  21Comments  路  Source: pinterest/ktlint

I just upgraded to Kotlin 1.4.0 from 1.3.72 and I get the following error

* What went wrong:
Execution failed for task ':app:formatKotlinAndroidTest'.
> There was a failure while executing work items
   > A failure occurred while executing org.jmailen.gradle.kotlinter.tasks.format.FormatWorkerRunnable
      > Could not initialize class com.pinterest.ktlint.core.ast.ElementType

I changed nothing else besides the kotlin version in my project. I'm using Detekt v1.11.0

Your Environment

  • Version of ktlint used: Detekt 1.11.0, ktlint 0.37.2
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):
  • Version of Gradle used (if applicable): 6.5.1
  • Operating System and version: Mac OS X 10.15.6

Most helpful comment

Ok artifacts should be uploaded. Gotta put the kiddos to bed but let me know if this is enough to unblock you all.

All 21 comments

Same...updated to latest detekt/ktlint and have same issue:

Exception in thread "main" java.lang.NoSuchFieldError: FUN_KEYWORD
--
聽 | at com.pinterest.ktlint.core.ast.ElementType.<clinit>(ElementType.kt:154)
聽 | at com.pinterest.ktlint.ruleset.standard.ChainWrappingRule.<init>(ChainWrappingRule.kt:36)
聽 | at com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider.get(StandardRuleSetProvider.kt:11)
聽 | at com.pinterest.ktlint.KtlintCommandLine.loadRulesets(Main.kt:546)
聽 | at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:222)
聽 | at com.pinterest.ktlint.Main.main(Main.kt:62)
聽 | Exception in thread "main" java.lang.NoSuchFieldError: FUN_KEYWORD
聽 | at com.pinterest.ktlint.core.ast.ElementType.<clinit>(ElementType.kt:154)
聽 | 聽
聽 | Exception in thread "main" java.lang.NoSuchFieldError: FUN_KEYWORDget(StandardRuleSetProvider.kt:11)
聽 | at com.pinterest.ktlint.core.ast.ElementType.<clinit>(ElementType.kt:154)
聽 | at com.pinterest.ktlint.ruleset.standard.ChainWrappingRule.<init>(ChainWrappingRule.kt:36)
聽 | at com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider.get(StandardRuleSetProvider.kt:11)
聽 | at com.pinterest.ktlint.KtlintCommandLine.loadRulesets(Main.kt:546)
聽 | at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:222)
聽 | at com.pinterest.ktlint.Main.main(Main.kt:62)

Indeed, we need to release a new version compiled against 1.4. In the meantime, you can try kotlin-dev snapshot, that is built with 1.4-rc and the exception you get should already be gone.

would you consider publishing a non-snapshot alpha/etc version that developers could use? Not sure what your time frame looks like

yeah, we were even considering releasing a stable version as the changelog is looking pretty packed already for the next version, but I am relying on @shashachu here as she's the one who makes releases usually

@romtsn You mentioned the latest snapshot build, but which one exactly? I tried 0.38.0-SNAPSHOT, but this build is 9 days old and fails with java.lang.NoClassDefFoundError: Could not initialize class com.pinterest.ktlint.core.ast.ElementType. Did you mean 0.38.0-kotlin-1.4-M2-SNAPSHOT? This build doesn't work either, because it's built with a preview build and Kotlin stable 1.4.0 doesn't allow using that.

Hi all, we're looking into this right now. It minimum we'll look to publish a snapshot build with the 1.4.0 release ASAP, but we'll aim to do a full release with 1.4.0 as soon as possible after.

Thanks @shashachu. Would you consider making it a published -alpha01 or similar non-snapshot build? I think most teams would be happy to pick up an alpha but a snapshot build incurs a build reproducibility cost that most teams probably can't afford to check in

I agree with Zac. Snapshot builds also use a different repository and it many codebases it's excluded. There's no downside for pushing an alpha version. Either way, it's very much appreciated.

Hi all, I've uploaded the Alpha01 executable jar here https://github.com/pinterest/ktlint/releases/tag/0.38.0-alpha01 but I'm having a fight with Sonatype so still working on getting the artifacts uploaded.

Thank you!

Ok artifacts should be uploaded. Gotta put the kiddos to bed but let me know if this is enough to unblock you all.

Thank you. This version definitely compiles, but comes with its own challenges. I filed a separate issue: #836

Sorry for miscommunication @vRallev, I thought publishing snapshots with latest Kotlin version already works, but apparently it's not

Worked for us. Thanks again for the quick turnaround on this!

Wow. Amazing work. 馃憦

I tried updating https://github.com/jeremymailen/kotlinter-gradle/blob/master/buildSrc/src/main/kotlin/Versions.kt accordingly to the alpha release (and kotlin 1.4.0) but I keep getting the following exception in its unit tests (and one of my projects):

'void kotlin.jvm.internal.FunctionReferenceImpl.<init>(int, java.lang.Object, java.lang.Class, java.lang.String, java.lang.String, int)'
java.lang.NoSuchMethodError: 'void kotlin.jvm.internal.FunctionReferenceImpl.<init>(int, java.lang.Object, java.lang.Class, java.lang.String, java.lang.String, int)'
    at com.pinterest.ktlint.core.KtLint$visitor$1.<init>(KtLint.kt)
    at com.pinterest.ktlint.core.KtLint.visitor$default(KtLint.kt:218)
    at com.pinterest.ktlint.core.KtLint.lint(KtLint.kt:164)
    at org.jmailen.gradle.kotlinter.support.RuleSetsTest.test compatibility(RuleSetsTest.kt:43)
    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)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    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)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:119)
    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)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.base/java.lang.Thread.run(Thread.java:834)

@jonasbark I've seen that error come up only when running 1.4-compiled kotlin bytecode in a 1.3 environment

Thanks for the alpha....'fraid it wasn't enough for us though...now we get this in a bunch of random places:

Exception in thread "main" java.lang.NoSuchFieldError: FUN_KEYWORD
--
聽 | at com.pinterest.ktlint.core.ast.ElementType.<clinit>(ElementType.kt:154)
聽 | at com.pinterest.ktlint.ruleset.standard.ChainWrappingRule.<init>(ChainWrappingRule.kt:36)
聽 | at com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider.get(StandardRuleSetProvider.kt:11)
聽 | at com.pinterest.ktlint.KtlintCommandLine.loadRulesets(Main.kt:546)
聽 | at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:222)
聽 | at com.pinterest.ktlint.Main.main(Main.kt:62)

Purely from a debugging perspective, it might help your debugging if you can dump out the line or region of our code that you get crashes in though I'm not sure it's possible.

Hi guys, I am also waiting for ktlint to support Kotlin 1.4.0.
Was not sure, that the alpha version is ready and opened a pull request yesterday with updating dependencies. Please have a look, any feedback is appreciated.
The build is compiling, checks are passing, the application is running. Couldn't publish it to maven local, though.
https://github.com/pinterest/ktlint/pull/838

Is there any chance to get another alpha build?

soon should be 0.38.0 release. Please create separate issues for any compatibility problems with Kotlin 1.4.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artnc picture artnc  路  3Comments

Tapchicoma picture Tapchicoma  路  3Comments

Jacksgong picture Jacksgong  路  3Comments

chao2zhang picture chao2zhang  路  4Comments

tonilopezmr picture tonilopezmr  路  4Comments