https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
g

GarouDan

02/03/2019, 3:54 PM
Hi guys, I asked this question on stackoverflow and I’ll appreaciate if someone could help me to find a workaround for this. https://stackoverflow.com/questions/54503916/is-it-possible-to-create-a-kotlin-multiplatform-project-referencing-the-correct I would like to know if this is a limitation or if we could change our configuration files to achieve the expected result.
e

egorand

02/03/2019, 7:33 PM
common modules don’t have targets, they’re pure platform-agnostic Kotlin. what’ you’re calling “common module with JVM target” is in fact a JVM module, so you have to point your Android modules to the JVM module, not the common module.
g

GarouDan

02/03/2019, 7:46 PM
Hi @egorand, thanks for commenting 😃 I don’t know if understood you correctly. The common module is a multiplatform module, the name could be different, like base or core, for example. Inside this module I have some presets / targets and, in fact, I would like to use two targets for the jvm but for different purposes (one for the api and the other for android). My commonMain and commonTest will still be platform agnostic. Maybe explaining on a different way, I would like to have a code common to all platforms (platform agnostic), a code that will be common to all android projects and a common code to all api projects, where the android and api projects are both related with the jvm. If I didn’t understand you, could you suggest a build.gradle configuration? Thanks in advance
e

egorand

02/03/2019, 9:21 PM
one thing that comes to mind is to use
dependsOn
inside the dependencies block of the target you’re configuring
e.g.
Copy code
dependencies {
  dependsOn jvmMain
}
g

GarouDan

02/03/2019, 10:03 PM
Yes, I’m doing this. The
jvmAndroid
and
jvmApi
source sets have a
dependsOn
relation with the
jvm
source set. But the problem is somehow a little different, because the android and api projects aren’t inside the “common” module, but outside, on different folders. If they were in the same module I agree that we could to something like that. For example, here in the kotlinconfapp, in the android project we have `implementation project(':common')`: https://github.com/JetBrains/kotlinconf-app/blob/88ec4e4bf3ee2c8eac7da9416e1b565a85fa2727/android/app/build.gradle#L48 And in the same project, in the api project, we also have the same line, `implementation project(':common')`: https://github.com/JetBrains/kotlinconf-app/blob/88ec4e4bf3ee2c8eac7da9416e1b565a85fa2727/backend/build.gradle#L12 This strategy works if we have just one api and one android project, where both share just one common jvm implementation. https://github.com/JetBrains/kotlinconf-app/blob/88ec4e4bf3ee2c8eac7da9416e1b565a85fa2727/common/build.gradle#L6 What I’m looking is something more flexible, so we could have a common code to not only jvm based projects, but 3 common codes. One for all jvm projects, one for android projects and one for api projects, for example. (Actually, I would like to extend this strategy to several other projects, but this is just a small case). In the way that the kotlinconf app is configured, it is exporting just one preset that is compatible with the jvm and we add this as a dependency using
implementation project(':common')
. So because of that I was asking if we could do something like
implementation project(':common:jvmAndroid')
or achieve a similar result.
e

egorand

02/03/2019, 10:07 PM
Oh, I see. Haven’t had experience with this kind of use cases unfortunately. Hoping somebody else can chime in
g

GarouDan

02/03/2019, 10:09 PM
Thanks a lot for your time 😃
👌 1
g

GarouDan

02/04/2019, 10:51 AM
Oh, thanks a lot @dany. This is exactly what I’m looking for. I’ll give it a try. Thanks a lot 😃
2 Views