I have gradle + multiplatform kotlin working. My standard setup is:
The gradle/kotlin-dsl/samples/multiplatform-* examples confuse me, as I don’t see the X-common, X-js, X-jvm directory structure.
I have tried converting my existing build.gradle to build.gradle.kts … but it’s not clear to me how various lines should be convertedc.
Question: Is there a minimal gradle kotlin-dsl example which follows the
They do? There aren’t any. You confused them with multi-project. As far as I can tell none of those examples have a multi-platform setup. This should not matter however.
You can follow those examples on how to setup the project structure. I guess you have to replace the plugin from kotlin("jvm") to kotlin("common"). I don’t know what exactly it is. You might need to experiment with the name a bit until you get it right. Then in the dependencies I guess you do exactly the same as you would using Groovy except with a slightly different syntax expectedBy(project(":-common"))
I am putting together a presentation to promote Kotlin, and want to use Kotlin’s common module as the main selling point unique to Kotlin. Unfortunately, being new to both gradle and multiplatform projects, I am having a really difficult time putting a sample together. I have already tried looking at KotlinAcademyApp for reference, but that one is way more complex than I need and is in fact so complex I have been unable to even get it to work with IntelliJ IDEA. kotlin-fullstack-sample is not workable either because it does not demonstrate testing.
You can find my (not working yet) sample project here:
Any help getting this up and running with the minimal possible configuration would be appreciated, I think it would benefit the Kotlin community to have a starting point like this to demonstrate the usefulness of common modules.
Your suggestion to take another look at https://kotlinlang.org/docs/reference/multiplatform.html helped me get the common module to build. I have updated the project and added the expectBy clauses as you suggest. Now I am trying to figure out how to invoke a common module from a regular module.
I am not sure if expectedBy applies in my case. I am not specifying that my JS and JVM modules provide the “actual” implementations of the “expect” declarations in common code. I am trying to get both JS and JVM regular modules to depend on code in the common module.
What I am envisioning is a large amount of common modules for my domain and libraries, depended on a few regular modules that handle launching the application and platform specific details. For this I expect I will not need platform modules at all, only regular modules and common modules.
Perhaps this is not the original intent, but I think it would be really useful and a great selling point for Kotlin.
It will be available (with the updated documentation) in the upcoming 1.3.20 release: https://youtrack.jetbrains.com/issue/KT-26389 . You can try it right now in the 1.3.20 EAP release (“1.3.20-eap-25” version of the plugin).
If that approach is used then sourceSets["jvmMain"].apply can be used in place of sourceSets.create() , but I see that the fromPresent can be omitted using the sourceSets.create() function. Is any thing lost by not using the fromPreset() approach, that cannot be added in other ways, and if so any idea how to add what is missed?
From preset does also set other data in the target which is not set by the create operation, but possibly can be manually applied in the apply block. Without ‘from preset’ , i cannot get the data for uploading the library to maven central. (this also requires a ‘pom’ block and this post may help with the pom ).
So more data about other settings for targets would be appreciated to allow not just building a multi-platform library, but also to allow publishing the multi-platform library.