Kotlin-dsl gradle, multi-platform project, minimal example


#1
  1. I am aware of https://github.com/gradle/kotlin-dsl/tree/master/samples and have read through the .kts files in the four multiplatform- folders .

  2. I have gradle + multiplatform kotlin working. My standard setup is:
    foobar-common/build.gradle
    foobar-jvm/build.gradle (expectedBy(":foobar-common"))
    foobar-js/build.grade (expectedBy(":foobar-common")

  3. The gradle/kotlin-dsl/samples/multiplatform-* examples confuse me, as I don’t see the X-common, X-js, X-jvm directory structure.

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

X-common/
X-jvm/
X-js/

directory structure?

Thanks!


#2

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


#3

I am trying to get a minimal example running as well, has anybody already done this? If not, can anyone point my existing project in the right direction? You can find it here https://github.com/SeanShubin/kotlin-prototype

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.

Sean


#4

Your missing the expectedBy part in the dependencies of js and jvm.
Take another look at the docs: https://kotlinlang.org/docs/reference/multiplatform.html

Also testing should be pretty simple. It works the same way it does with any kotlin gradle project. There is nothing special to do, except adding the right dependencies.


#5

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.


#6

Just need to get the JavaScript tests to actually run.

I do indeed need the expectedBy. I am really close now. The JVM tests are working fine, properly delegating to common code. I did the same thing with the javascript module but it seems the test simply do not run when I type “gradle test”. Anyone know what I am missing? It is probably something really simple that I am just not seeing.


#8

You can mute this topic by clicking on the “Tracking” button at the bottom, or by clicking on the blue icon below the right-hand side scroll bar.


#9

Sure, I thought my question was a duplicate (minimal, multi-platform project) so did not want to spam with a new topic, but am happy to post as a separate thread as well.