https://kotlinlang.org logo
Title
m

Matt Groth

05/03/2023, 5:26 PM
I have a question about configuring my Hierarchical Project Strucutre. First to give some contex. Say I have a project that contains two source sets:
jvm
and
js
.
common
is automatically created as well. Code in the
common
module cannot contain java classes or js classes. The only things that are allowed in
common
are those thar are compatible with
jvm
and
js
. Now say I have another project. This one only has a single source set:
jvm
.
common
is still autoamtically created. However, in this case,
common
is allowed to contain java classes. My understanding is that kotlin Multiplatform automatically configures
common
to allow anything that would be able to compile for each target in the project. Here is my question. I do not want
common
to behave differently depending on the targets that exist in a particular subproject. Rather, I would like for
common
to mean the same exact thing in each subproject regardless of the targets present. If I take a project that only has a single
jvm
source set, and want to add a
js
source, I want to know that the
common
source set will automatically be compatible. However, I do not want to add a
js
and a
jvm
source set to every single subproject, even if they would be blank. Basically, I want to disable the feature that configures
common
to have different dependencies based on which source sets are present. If I want to have a common source set that contains java classes for say, jvm desktop + android, then I will create this source set manually or with the incubating hierarchy template feature.
e

ephemient

05/03/2023, 5:34 PM
Kotlin compiler doesn't know what is common to all platforms, it only knows about the platform it is currently building for (common code gets rebuilt for each target platform) so it's not really a feature to "disable"
the feature you are looking for is https://youtrack.jetbrains.com/issue/KT-33578 but as of now, there is no solution
j

jw

05/03/2023, 5:37 PM
It also doesn't know about future targets. Maybe WASM prevents using something that every other target allows. Now when you update your Kotlin version to one with WASM support what behavior should happen? All your code stops compiling?
m

Matt Groth

05/03/2023, 5:37 PM
Thanks for sharing the YouTrack issue. That’s pretty much what I am looking for.
I want it to know about which targets to support without necessarily adding those targets. I will tell it whether or not to support wasm, without necessarily adding wasm.
I added a comment to that youtrack issue.