https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hiring-french
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
m

mkrussel

07/13/2022, 4:21 PM
I'm trying to upgrade Kotlin to 1.7.0 and I'm no longer able to get my
buildSrc
project to configure. It's breaking on applying the
kotlin-dsl
plugin.
An exception occurred applying plugin request [id: 'org.gradle.kotlin.kotlin-dsl', version: '2.3.3']
> Failed to apply plugin class 'org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper'.
   > Could not create an instance of type org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension.
      > Companion
Gradle version: 7.3.3 Kotlin version: 1.7.0 kotlin-dsl version: 2.2 and 2.3.3
Some of the stack trace
Caused by: java.lang.NoSuchFieldError: Companion
        at org.jetbrains.kotlin.gradle.dsl.ToolchainSupport$Companion.createToolchain$kotlin_gradle_plugin(ToolchainDsl.kt:33)
        at org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension.<init>(KotlinProjectExtension.kt:69)
        at org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension.<init>(KotlinProjectExtension.kt:109)
        at org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension.<init>(KotlinProjectExtension.kt:118)
        at org.jetbrains.kotlin.gradle.dsl.KotlinSingleJavaTargetExtension.<init>(KotlinProjectExtension.kt:124)
        at org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension.<init>(KotlinProjectExtension.kt:128)
        at org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension_Decorated.<init>(Unknown Source)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at org.gradle.internal.instantiation.generator.AsmBackedClassGenerator$InvokeConstructorStrategy.newInstance(AsmBackedClassGenerator.java:2070)
        at org.gradle.internal.instantiation.generator.AbstractClassGenerator$GeneratedClassImpl$GeneratedConstructorImpl.newInstance(AbstractClassGenerator.java:488)
        at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:64)
        ... 311 more
m

mbonnin

07/13/2022, 5:05 PM
You can't really use 1.7.0 in
buildSrc
because Gradle uses something else (1.5 most likely). Your best bet is to use
plugins {
  `embedded-kotlin`
}
or
plugins {
  `kotlin-dsl`
}
Oh wait, looks like this is what you're doing already 🤔
Can you build your
buildSrc
project separately?
./gradlew -p buildSrc build
m

mkrussel

07/13/2022, 5:13 PM
no I also tried adding the
embedded-kotlin
plugin but still no luck. When I did revert back to 1.6.21 the warning about incompatible kotlin versions went away, but I still cannot build with 1.7.0.
m

mbonnin

07/13/2022, 5:14 PM
buildSrc
should know nothing about 1.6 vs 1.7
``kotlin-dsl`` will choose the correct version of Kotlin to use based on your Gradle version
If you have a manually defined Kotlin version in
buildSrc
, that's most likely the cause of your error
m

mkrussel

07/13/2022, 5:16 PM
I have not defined in in
buildSrc
but I do use
kotlin("plugin.serialization") version "1.6.21"
in the plugins.
m

mbonnin

07/13/2022, 5:18 PM
I guess that's in a convention plugin somewhere?
m

mkrussel

07/13/2022, 5:18 PM
Yes
m

mbonnin

07/13/2022, 5:18 PM
buildSrc/src/main/kotlin/my.convention.gradle.kts
or so?
m

mkrussel

07/13/2022, 5:18 PM
Does the version of dependencies for the actual source code impact what is used when loading the plugins?
m

mbonnin

07/13/2022, 5:19 PM
Define "actual" 😅
m

mkrussel

07/13/2022, 5:19 PM
Actually everything in the
buildSrc
are
.kt
files no
.kts
files
m

mbonnin

07/13/2022, 5:20 PM
m

mkrussel

07/13/2022, 5:20 PM
Actual being what is declared in the dependency section of the gradle file but not the buildscript dependencies. So the dependencies that the Kotlin source code links with.
m

mbonnin

07/13/2022, 5:22 PM
I mean you have multiple gradle files and buildscript there so it's hard to tell
What I'd do is move from
kotlin-dsl
to
embedded-kotlin
and rewrite the convention plugins as regular
.kt
files, it might be easier to see where the problem is
Plus you'd save some build time
m

mkrussel

07/13/2022, 5:24 PM
It was the dependencies, when I downgraded them all to ones that use an older version of kotlin the error goes away.
Thanks for all your help.
m

mbonnin

07/13/2022, 5:26 PM
Sure thing! Glad you found a solution!
m

mikehearn

07/14/2022, 12:50 PM
This is the same problem discussed earlier in this channel. https://kotlinlang.slack.com/archives/C19FD9681/p1656593570021959
There seems to be no way to upgrade to Kotlin 1.7 currently when using the standard project layout created according to the Gradle docs, because the kotlin version used by the project and by the build get conflated.
m

mbonnin

07/14/2022, 1:01 PM
@mikehearn do you have a reproducer? I'm pretty sure you can use 1.7 in your main build while still using the embedded Kotlin version for your `buildSrc`/`convention plugins`
m

mikehearn

07/14/2022, 1:03 PM
In the thread above a whole lot of people worked with me on it, and we got nowhere. It never worked. It did result in a PR to the gradle docs, but, the underlying issue remains. There's no obvious way to specify a version of Kotlin for your project but not the build script - the attempts I made all failed with different errors 😞
mkrussel seems to reach the same point as me - he downgrades to older kotlin again
m

mbonnin

07/14/2022, 1:05 PM
How do I reproduce ? Follow the steps at https://docs.gradle.org/current/samples/sample_building_kotlin_applications_multi_project.html and bump the kotlin version?
mbonnin:~/git/demo$ ./gradlew :app:run            

> Task :app:run
Hello World! 1.7.0

BUILD SUCCESSFUL in 484ms
m

mikehearn

07/14/2022, 1:21 PM
The issue is caused by common plugins.
The thread above ends with sort of concluding that there's some plugin that is causing conflicts because it depends on kotlin, but there's no easy way to figure out which one. So ... we wait for Gradle to upgrade Kotlin to 1.7 and hope the issue goes away.
Or something like that. Don't quite recall. It seems like a common problem though.
m

mbonnin

07/14/2022, 1:22 PM
In that case yes but it's an issue from a specific plugin, not a general issue with 1.7
m

mikehearn

07/14/2022, 1:24 PM
Right Kotlin itself is fine, but lots of projects are stuck due to this issue. I shared the build.gradle.kts before and even disabled some plugins but it didn't help, the only ones left are all common (like dokka). Could try again soon and see if there are many new plugin versions that fix it but for now we gave up. It's too hard to upgrade Kotlin with Gradle and when things break, the errors don't help 😞
m

mbonnin

07/14/2022, 1:25 PM
FWIW, we shadow
kotlin-stdlib
in our plugins to avoid exactly that issue. I wrote about it there: https://blog.mbonnin.net/use-latest-kotlin-in-your-gradle-plugins
If you have a specific plugin that doesn't work, it's worth opening an issue there as it's fixable/workaroundable
I know that situation is far from ideal but getting stuck on older versions of Kotlin isn't ideal either...
m

mikehearn

07/14/2022, 1:27 PM
Problem was, I couldn't figure out which was doing it. Disabling more and more plugins is one way but then that would just break the build, as parts do depend on those plugins.
m

mbonnin

07/14/2022, 1:31 PM
Can you share all your plugins with versions?
m

mikehearn

07/14/2022, 1:36 PM
https://gist.github.com/mikehearn/4c2a5ccfb3d222fa28805cf12b2c53e0 NB: The powerassert and arrow analysis plugins are/were known to not work on 1.7 but even with them disabled, there was no difference. Generally all the obviously optional ones were commented out and disabled, but no dice.
👀 1
m

mbonnin

07/14/2022, 1:36 PM
Perfect 👌
You can see the dependencies with
./gradlew -p buildSrc dependencies
, that should show which one is pulling Kotlin 1.7
In that specific case,
kotlin-reflect
is pulling
kotlin-stdlib:1.7.0
You can either: • remove kotlin-reflect from your dependencies • or workaround by disabling the metadata version check:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java) {
    kotlinOptions {
        freeCompilerArgs = freeCompilerArgs + "-Xskip-metadata-version-check"
    }
}
m

mikehearn

07/14/2022, 2:01 PM
Ah, this rings a bell. Refreshing my memory from the other thread, I wrote this:
OK - partial success! After removing that reflect line and the three plugins, I can get a build with Kotlin 1.7, woop! Thanks! Unfortunately, re-enabling Dokka and upgrading it to Dokka 1.7.0 brings back the same metadata version mismatch error as before.
So it seemed at the time we have to choose between Dokka and Kotlin 1.7, and Dokka is more important. Perhaps there's been a new release since that fixes this.
This was only two weeks ago though.
m

mbonnin

07/14/2022, 2:02 PM
Yea, just tried with dokka and for some reason 1.7.10 still pulls the stdlib 😞
So somewhat looks like my fix didn't work 🤔
m

mikehearn

07/14/2022, 2:07 PM
I should commit the removed reflect dep anyway though, thx for the reminder. I think I just got frustrated and rolled everything back as by that point the build was pretty hacked up.
👍 1
m

mbonnin

07/14/2022, 2:08 PM
Something's weird with the dokka 1.7.10 release 🤔 I don't have the issue if I build locally
Or maybe something's weird with my local setup. Investingating, I'll update this thread
m

mikehearn

07/14/2022, 2:08 PM
Thanks!
m

mbonnin

07/14/2022, 2:10 PM
Fun stuff: the dokka:1.7.10 from
mavenCentral()
isn't the same as the dokka:1.7.10 from
gradlePluginPortal()
m

mikehearn

07/14/2022, 2:11 PM
Oof 😞
i

Ignat Beresnev

07/14/2022, 4:46 PM
Hi! Yeah, sorry to hear Dokka is getting in the way. You can have a look at the issue, there's some workarounds https://github.com/Kotlin/dokka/issues/2546
m

mikehearn

07/14/2022, 4:47 PM
Thanks. I think we'll wait. 1.7 is a nice upgrade but not urgent. Once it's all sorted out, then we'll try again
m

mbonnin

07/14/2022, 4:54 PM
For Dokka, you can use dokka 1.7.10 and do the following:
repositories {
    mavenCentral()
    gradlePluginPortal {
        content {
            // Might not even be needed since mavenCentral() should take precedence
            excludeGroup("org.jetbrains.dokka")
        }
    }
}
That + removing the kotlin-reflect line should make your project compile
I filed this issue on Arrow but this is only warnings. I think it shouldn't prevent you to build
If you ever have another issue, please report them, the sooner we get them fixed, the sooner the ecosystem can move forward
m

mikehearn

07/14/2022, 4:58 PM
Thanks!
I'll try that soon.
:thank-you: 1
👍 1
m

mbonnin

07/14/2022, 4:58 PM
In other news, Gradle 7.5 is out 🎉 : https://docs.gradle.org/7.5/release-notes.html
i

Ignat Beresnev

07/14/2022, 5:22 PM
Updating to it also solves the problem, right?
m

mbonnin

07/14/2022, 5:22 PM
Yep, most likely. Gradle 7.5 (with embedded Kotlin 1.6) can read the Kotlin 1.7 metadata
Because there's a 1 version "forward compatibility"