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
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

Mike Dawson

03/27/2023, 4:24 PM
As I understand from this bug - https://youtrack.jetbrains.com/issue/KT-43500 - it seems like IR Javascript compilation fails when dealing with any compileOnly dependency. Now that the Legacy compiler is deprecated, this would mean that compileOnly dependencies cannot be used for Javascript at all. That seems very unfortunate.
b

Big Chungus

03/27/2023, 4:38 PM
What's your use-case for such dependencies in js?
m

Mike Dawson

03/27/2023, 4:41 PM
My use case is as follows: I have created a symbol processor that makes Android's Room work with Kotlin multiplatform (by generating JVM/JS code). Now I need to be able to use Androidx.room annotations on code that I want to compile on JVM/JS. So I created a module with copies of those annotations, and included it as a compileOnly dependency. If I use an implementation dependency, then I would get a duplicate class error. I think my use case is the standard use case for compileOnly: I want to compile against one implementation, but then be able to use a different implementation at runtime.
b

Big Chungus

03/27/2023, 4:44 PM
I see, I think rather than plain copying jvm room annotations, you should create a kmp module that declares expect/actual for those annotations and just typealias them to room annotations on jvm actuals. This is a solution to your immediate problem and NOT an argument against your use-case for compileOnly dependency support
m

Mike Dawson

03/27/2023, 4:46 PM
Thanks, I did try going down the expect/actual path - but I hit two big problems: 1. You can't include default values in the expect declaration if you use a typealias. So that means any multiplatform code would have to explicitly specify every argument and defaults wouldn't work
b

Big Chungus

03/27/2023, 4:46 PM
Although now that I think about it, it might not be an issue with compileOnly, but rather incorrect kmp dependency module that doesn't support all required targets
m

Mike Dawson

03/27/2023, 4:48 PM
2. The symbol processor (since 1.7) won't resolve expect/actual annotations by default. The annotation processor author has to do that themselves. So when Room's own annotation processor runs, it won't recognize expect/actual as the same thing
b

Big Chungus

03/27/2023, 4:48 PM
Legacy js compiler was known to be very lax when it came to enforcing kmp requirements
When room runs it should see only room annotations on jvm. No idea what happens on js
m

Mike Dawson

03/27/2023, 4:48 PM
It definitely isn't an issue with supporting all kmp targets: I used the same code on JVM and JS
I used a shared source set... e.g. for all non-Android supported targets
b

Big Chungus

03/27/2023, 4:49 PM
Got it, I might be wrong then
You mean without declaring all the targets on shared that the consumer module uses?
m

Mike Dawson

03/27/2023, 4:50 PM
Sorry I don't understand what you mean "without declaring all target on shared that the consumer module uses?"
b

Big Chungus

03/27/2023, 4:51 PM
In order to use a kmp library, it must declare and be compiled for all the targets that your consumer uses
m

Mike Dawson

03/27/2023, 4:52 PM
That is the case... they are both my projects...
b

Big Chungus

03/27/2023, 4:52 PM
For example if you have a module that declares js and jvm targets, you can only use libs in commonMain that also declare js and jvm
m

Mike Dawson

03/27/2023, 4:52 PM
The module itself compiled for JS(BOTH), JVM, and Android
the consumer would compile for Js(legacy), JVM, and Android
b

Big Chungus

03/27/2023, 4:52 PM
Regardless if the lib is remote (mavenCentral) or local (module)
m

Mike Dawson

03/27/2023, 4:53 PM
But if I set the consumer to Js(IR) - then I get the same as error as mentioned on the bug report
b

Big Chungus

03/27/2023, 4:53 PM
Gotcha, ignore all I said then. Looks like your kmp setup is correct at the very least 😀
Note that that particular error is very generic and happens in many different cases, not just the ones reported there.
m

Mike Dawson

03/27/2023, 4:54 PM
For now, I could try using exclude on gradle to try and block an implementation dependency from coming into Android
Yes - I see the error itself is quite generic - but what struck me is what I'm doing is exactly the same - using compileOnly for an annotation dependency
My point being to not discount the possibility that your issue might be unrelated
m

Mike Dawson

03/27/2023, 4:56 PM
I really hope not - I have spent most of the days working on / trying/ thinking about ways around it.
I will try using the dependency as an implementation and exclude to avoid it coming onto Android. Not ideal, but could workaround the issue for now. If that works, I'll message back and maybe add to the discussion on the bug report.
b

Big Chungus

03/27/2023, 4:57 PM
You're not alone, lots of people have wasted days on that error
m

Mike Dawson

03/27/2023, 4:58 PM
The bug report does have an attached basic reproduction case... that was done back in Kotlin 1.4 days...
I think it would be worth testing the reproduction case against Kotlin 1.8 - if it still doing that, then I think it is something that really needs looked at. compile only transitive dependencies are a standard feature, so if IR is now the production system, it should handle that
b

Big Chungus

03/27/2023, 5:03 PM
Agreed, especially since IR is in beta already
No, wait. It's stable already since 1.8
m

Mike Dawson

03/27/2023, 5:05 PM
Legacy is deprecated as I understand... all Kotlin/JS has to move over to IR
Exclude dependencies feature missing on Kotlin Multiplatform - oh goodie: https://youtrack.jetbrains.com/issue/KT-31340/Exclude-transitive-dependencies-for-project-dependencies
Sure enough - after I remove use of compileOnly in the dependency, the consumer app compiles using IR on Javascript