Starting to migrate to 2.1.0 in our company and we...
# gradle
h
Starting to migrate to 2.1.0 in our company and we're seeing this on some of the Gradle builds
Copy code
Caused by: org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
        at org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:89)
        at org.jetbrains.kotlin.protobuf.CodedInputStream.readTag(CodedInputStream.java:158)
        at org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf$Module.<init>(JvmModuleProtoBuf.java:223)
Seeing the most recent instance of this error here - https://youtrack.jetbrains.com/issue/KT-59139/1.9.0-BetaK2-Protocol-message-contained-an-invalid-tag-zero.-during-project-configuration
m
What is your Gradle version?
h
For this particular project, I believe Gradle 7.6.4
Let me actually take a look and see if a similar project with the latest Gradle 8 fails
m
You'll need 8.3 if my memories are correct. Edit, not correct, it was 8.11
7.6 definitely won't do
h
These were working fine with 2.0.21, but well ...
m
The Kotlin compiler has n+1 forward compatibility
Compiler 1.9 can read 2.0 libraries
You need Compiler 2.0 to read 2.1 libraries
h
Yeah that sounds about right. Let me try to upgrade these packages to Gradle 8 and see if that solves it
m
8.3 πŸ˜‰
h
Internally, we only have a version of Gradle 8 which is 8.11, so we should be fine πŸ˜„
πŸ‘ 1
m
Oh ok, that's more than fine πŸ‘
h
Copy code
java.lang.NoSuchMethodError: 'org.gradle.internal.buildoption.BuildOption$Value org.gradle.api.internal.StartParameterInternal.getIsolatedProjects()'
        at org.jetbrains.kotlin.gradle.plugin.internal.ProjectIsolationStartParameterAccessorG76$isProjectIsolationEnabled$2.invoke(ProjectIsolationStartParameterAccessorG76.kt:16)
        at org.jetbrains.kotlin.gradle.plugin.internal.ProjectIsolationStartParameterAccessorG76$isProjectIsolationEnabled$2.invoke(ProjectIsolationStartParameterAccessorG76.kt:15)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
Interestingly, a different error\
m
Just realized that you do really need 8.11, 8.3 is embedding 1.9 which is most likely not working
java.lang.NoSuchMethodError: 'org.gradle.internal.buildoption.BuildOption$Value org.gradle.api.internal.StartParameterInternal.getIsolatedProjects()'
Yup', that's a new one!
You probably need to update KGP now πŸ˜…
h
https://youtrack.jetbrains.com/issue/KTIJ-31860/Sync-failure-when-using-Kotlin-2.1.20-dev-1129#focus=Comments-27-11093040.0-0 - it seems our Gradle friends have refactored their code and removed this function that Kotlin relies on. I guess we're not going to be upgrading to Kotlin 2.1.0 anytime soon πŸ˜…
Actually, I'm seeing a few projects that build with Gradle 7.6.4 + Kotlin 2.1.0. Likely some different behaviour being used that is now broken
m
Depends what you have in your buildscript classpath
And whether you use
build.gradle.kts
h
these particular packages are using
build.gradle
m
This is why
h
so you're effectively saying that build.gradle is likely going to make a package "last longer"?
m
I don't know if I would phrase it like that but
build.gradle
files are not exposed to Kotlin compatibility issues
h
This guy is going to be so happy when I share this with him ... He isn't a Groovy apologist but he doesn't like that Gradle is pushing so hard to use the
build.gradle.kts
files.
🍿 2
m
That debate never gets old!
h
For reference - https://kotlinlang.org/docs/whatsnew21.html#gradle-improvements
Kotlin 2.1.0 is fully compatible with Gradle 7.6.3 through 8.6. Gradle versions 8.7 to 8.10 are also supported, with only one exception. If you use the Kotlin Multiplatform Gradle plugin, you may see deprecation warnings in your multiplatform projects calling the `withJava()` function in the JVM target. We plan to fix this issue as soon as possible.
Seems like the protobuf issue is related to something else
m
KGP is compatible with gradle 7.6: you can compile 2.1.0 libs with Gradle 7.6. But you can not use these libs in your 7.6 buildscripts . It's 2 different things
h
Ah, clear. I'll be recommending everyone to upgrade to Gradle 8 (which they should've already done - we created a script for it)
Internally, we've observed that this always happens with Gradle 7.6.4 projects (we only have either 7.6.4 or 8.11.1)
m
There's no much the Kotlin team can do, you have to upgrade your Gradle version
h
In theory, the
main
variant should support it though
m
What do you mean by the
main
variant?
image.png
the Kotlin Gradle Plugin has several variants aiming to work with specific Gradle versions (and yes, 7.6.4 specifically isn't there, I'm not sure if this is on purpose. I'd be happy to roll it back to 7.6.3 if it makes it work)
m
It's the same answer I made there: KGP can build libs with Gradle 7.6.4. What's not working is using those libs in your buildscript classpath.
h
Oh right, I forgot - if we were to use
build.gradle
, it would work
m
if we were to use
build.gradle
, it would work
Not even sure. You wouldn't get the "invalid tag" error (because this one is happening when compiling your build scripts). But you could get runtime errors from your Gradle build referencing inexisting APIs
If you're using
buildSrc
or
build-logic
, you must downgrade apiVersion and languageVersion there and make sure no buildscript dependency uses kotlin-stdlib:2.1+
In all cases, I wouldn't say this is a Kotlin issue.
h
I have a couple of 7.6.4 projects that are indeed working, but they're all using
brazil.gradle
Waiting for the latest dryrun to finish to see if I can find other examples
m
I have a couple of 7.6.4 projects that are indeed working, but they're all using
brazil.gradle
Assuming you meant
build.gradle
? That can work indeed. But the compile-time stdlib is different from the runtime stdlib. It's only working because none of the code references "newer" APIs
πŸ‘ 1