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

GarouDan

01/30/2019, 11:52 PM
Good evening guys = ) Is it possible to have a mpp module without any presets / targets? My motivation to this is that I would like to create a common module without any targets / presets, just source sets, and them, in other modules, add this as a dependency. For example in desktop, mobile or backend modules. So I could use something like:
implementation project(':common')
If I put at least one preset / target it seems to work, but without any preset / target it isn’t working. Do you know if we can change our
build.gradle
to achieve this result?
h

hmole

01/31/2019, 8:00 AM
If you want to consume it from jvm, you neeed jvm preset. Simularly with others platform. But you don't have to have any code in your target sourceSets, only in common
n

nestserau

01/31/2019, 8:04 AM
You need to have at least one target, otherwise what do you expect your project to consume as a dependency? It has to be compiled first. And then according to your metadata the proper target will be chosen by the consumer.
r

ribesg

01/31/2019, 8:43 AM
If you want platform-dependent dependencies, then you need to use that platform’s target. If you don’t, then you don’t want a target but just another sourceSet @GarouDan
g

GarouDan

01/31/2019, 11:04 AM
Thanks guys 😃. So if I would like to use this code on all possible platforms I need to create a preset for each of them and configure its source sets to depend the common one and nothing more. Is that right?
@ribesg, unfortunately another source set will not really help me, since I would like to have the applications in other folders. For example a folder for the android app, another for the api, another for ios and so on. And looking for the kotlin example to build an application with android and ios, for example, it looks like it is not possible to have all projects living in the same folder. It’s somehow what I would like to try.
r

ribesg

01/31/2019, 11:07 AM
Projects and folders are not the same thing, and a sourceSet is basically a folder with dependencies
I have a single project (one build.gradle.kts file) and I have multiple sourceSets/folders under my root
src
folder
You can define as many sourceSets as you want, they don’t need to be linked to a target. Any sourceSet can depend on any other sourceSet with
dependsOn
Basically, when you define a target it will define one (or more) sourceSets automagically associated to this target, but the link between targets and sourceSets ends there
g

GarouDan

01/31/2019, 11:09 AM
Yes, I understand your point. I already know that, indeed I have a lot of source sets. My doubt is that I would like to use this code from another folder / project outside.
r

ribesg

01/31/2019, 11:10 AM
Well if you have something in one project that you need to use in another project, then that thing needs to be a project
g

GarouDan

01/31/2019, 11:13 AM
Just to make sure we are understanding each other. If we have two projects (in the same repository). One living in the folder
common
and the other one living in the folder
android
(where we could have some other ones on different folders, but I simplifying here for brevity). Do you think that is possible to use the
common
project inside the
android
project (maybe using something like
implementation project(':common')
) without defining any presets in the
common
project?
n

nestserau

01/31/2019, 11:32 AM
For
common
to be able to be consumed by
android
, you need a
jvm
or
android
target in
common
.
g

GarouDan

01/31/2019, 11:37 AM
Ok, I understand how it works now = ) Thanks a lot all of you