# Kotlin 1.3-M2: new multiplatform projects model

**URL:** <https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264>\
**Category:** EAP\
**Created:** [August 30, 2018, 8:55am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264 "2018-08-30T08:55:33Z")\
**Posts on this page:** 20\
**Page:** 6

<div class="post-metadata">

**Author:** ![wild\_lynx](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wild_lynx/32/6767_2.png) [@wild\_lynx](https://discuss.kotlinlang.org/u/wild_lynx)\
**Post date:** [November 15, 2018, 11:42am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/106 "2018-11-15T11:42:11Z")

</div>

I believe there are some problems with Android configuration which aren’t actually related to MPP. To find out the root issue, try some additional logging, described [here](https://stackoverflow.com/questions/43848845/errorexecution-failed-for-task-appcompiledebugkotlin-compilation-error) — stack traces will help you to get the idea what’s actually wrong with that. So far, it’s hard to diagnose what is the problem, not enough information for that.

---

<div class="post-metadata">

**Author:** ![wild\_lynx](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wild_lynx/32/6767_2.png) [@wild\_lynx](https://discuss.kotlinlang.org/u/wild_lynx)\
**Post date:** [November 15, 2018, 12:42pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/107 "2018-11-15T12:42:19Z")

</div>

As to `shadow` plugin (`com.github.johnrengelman.shadow`), the situation is as follows.

- in case of using `jvmWithJava` target, it should work as is, just apply it from the top level of the `build.gradle` script. Note, hovewer, that the target is going to be deprecated as it’s already [said above](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/84).

- when using with `jvm` target, an additional task definition is needed, like the following:

The support of kotlin-frontend plugin for JS is in progress right now, you may track the progress via [this](https://youtrack.jetbrains.com/issue/KT-27249) issue.

---

<div class="post-metadata">

**Author:** ![bradchristie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/bradchristie/32/5523_2.png) [@bradchristie](https://discuss.kotlinlang.org/u/bradchristie)\
**Post date:** [November 15, 2018, 6:56pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/108 "2018-11-15T18:56:18Z")

</div>

Generated a stack trace, saved to  
[https://scans.gradle.com/s/kckuuohn2u23q/console-log](https://scans.gradle.com/s/kckuuohn2u23q/console-log)  
For now, got it working by hooking my task onto compileDebugSources

---

<div class="post-metadata">

**Author:** ![bradchristie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/bradchristie/32/5523_2.png) [@bradchristie](https://discuss.kotlinlang.org/u/bradchristie)\
**Post date:** [November 15, 2018, 6:58pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/109 "2018-11-15T18:58:38Z")

</div>

That specific task did not work, but with your idea of using a specific task found **compileDebugSources** which does work

---

<div class="post-metadata">

**Author:** ![leonid](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@leonid](https://discuss.kotlinlang.org/u/leonid)\
**Post date:** [November 16, 2018, 2:32am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/110 "2018-11-16T02:32:32Z")

</div>

> [@wild\_lynx](#):
>
> apply plugin: ‘kotlin-multiplatform’

thank you for reply, i’m tried shadow plugin in this way:

```
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
    }
}

plugins {
    id 'kotlin-multiplatform' version '1.3.10'
    id 'kotlinx-serialization' version '1.3.10'
}

apply plugin: 'com.github.johnrengelman.shadow'

repositories {
    jcenter()
    mavenCentral()
    maven { url "https://dl.bintray.com/kotlin/ktor" }
    maven { url "https://kotlin.bintray.com/kotlinx" }
    maven { url "http://dl.bintray.com/kotlin/kotlin-eap" }
    maven { url "http://dl.bintray.com/kotlin/kotlin-js-wrappers" }
}

kotlin {
    ext.ktor_version = '1.0.0-beta-4'
    ext.serialization_version = '0.9.0'

    targets {
        fromPreset(presets.jvm, 'jvm')
        fromPreset(presets.js, 'js')
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        jvmMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
                implementation 'org.jetbrains.exposed:exposed:0.9.1'
                implementation "io.ktor:ktor-server-netty:$ktor_version"
                implementation "io.ktor:ktor-gson:$ktor_version"
                implementation "io.ktor:ktor-client-core:$ktor_version"
                implementation "io.ktor:ktor-client-cio:$ktor_version"
                implementation "io.ktor:ktor-locations:$ktor_version"
                implementation "io.ktor:ktor-html-builder:$ktor_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
                implementation "mysql:mysql-connector-java:8.0.7-dmr"
            }
        }
        jvmTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
            }
        }
        jsMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
                implementation 'org.jetbrains:kotlin-react:16.6.0-pre.59-kotlin-1.3.0'
                implementation 'org.jetbrains:kotlin-react-dom:16.6.0-pre.59-kotlin-1.3.0'
            }
        }
        jsTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-js'
            }
        }
    }
}

task shadowJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
    def target = kotlin.targets.jvm
    from target.compilations.main.output
    def runtimeClasspath = target.compilations.main.runtimeDependencyFiles
    configurations = [runtimeClasspath]
    println "task shadow jar"
}

```

it builds but jar is not fat…

---

<div class="post-metadata">

**Author:** ![h0tk3y](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/h0tk3y/32/1781_2.png) [@h0tk3y](https://discuss.kotlinlang.org/u/h0tk3y)\
**Post date:** [November 16, 2018, 1:43pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/111 "2018-11-16T13:43:40Z")

</div>

@leonid  
I tried your build script, and by running `./gradlew shadowJar` I got a fat JAR under `build/libs/test-project.jar` which contains the dependencies:

```bash
$ unzip build/libs/test-project.jar
$ tree build/libs/test-project -L 2 -d
.
├── com
│ ├── google
│ ├── mysql
│ └── typesafe
├── io
│ ├── ktor
│ └── netty
├── junit
│ ├── extensions
│ ├── framework
│ ├── runner
│ └── textui
├── kotlin
│ ├── annotation
│ ├── collections
│ ├── comparisons
│ ├── concurrent
│ ├── contracts
│ ├── coroutines
│ ├── experimental
│ ├── internal
│ ├── io
│ ├── jdk7
│ ├── js
│ ├── jvm
│ ├── math
│ ├── properties
│ ├── random
│ ├── ranges
│ ├── reflect
│ ├── sequences
│ ├── streams
│ ├── system
│ └── text
├── kotlinx
│ ├── atomicfu
│ ├── coroutines
│ ├── html
│ ├── io
│ └── serialization
├── META-INF
│ ├── maven
│ ├── proguard
│ └── services
└── org
    ├── eclipse
    ├── hamcrest
    ├── intellij
    ├── jetbrains
    ├── joda
    ├── json
    ├── junit
    └── slf4j

```

Is your result different? What do you mean by ‘jar is not fat’?

---

<div class="post-metadata">

**Author:** ![h0tk3y](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/h0tk3y/32/1781_2.png) [@h0tk3y](https://discuss.kotlinlang.org/u/h0tk3y)\
**Post date:** [November 16, 2018, 1:56pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/112 "2018-11-16T13:56:32Z")

</div>

@leonid Note that the shadow JAR is created alongside with the normal JAR for the JVM target. The normal JAR is suffixed with `-jvm`. It is up to you to replace the normal JVM JAR with the fat one whenever it is used or published.

---

<div class="post-metadata">

**Author:** ![leonid](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@leonid](https://discuss.kotlinlang.org/u/leonid)\
**Post date:** [November 19, 2018, 1:26am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/113 "2018-11-19T01:26:05Z")

</div>

yes, it works, thank you

---

<div class="post-metadata">

**Author:** ![luca992](https://avatars.discourse-cdn.com/v4/letter/l/f17d59/32.png) [@luca992](https://discuss.kotlinlang.org/u/luca992)\
**Post date:** [November 27, 2018, 6:11pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/114 "2018-11-27T18:11:36Z")

</div>

> [@h0tk3y](#):
>
> UPD: make sure that the top-level `dependencies { ... }` where you add a Kapt is placed _after_ the `kotlin { ... }` block where the Android target is defined.

You guys should really add this to documentation.

---

<div class="post-metadata">

**Author:** ![marco89nish](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@marco89nish](https://discuss.kotlinlang.org/u/marco89nish)\
**Post date:** [December 16, 2018, 5:12pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/115 "2018-12-16T17:12:18Z")

</div>

@wild_lynx Hi, I’ve tried creating a project from template (Kotlin - Mobile Android and iOS) in Idea 2018.3.1, kotlin plugin 1.3.11-release-IJ2018.3-1, gradle 4.7. I’ve tried adding jvm target for ktor server I planned and building that target throws this error `Error:Kotlin: Unsupported plugin option: org.jetbrains.kotlin.android:enabled=true`.  
Looking at module setting, it appears that all targets/submodules/sourcesets have android plugin enabled in “Compiler Plugins” tab. I’ve tried removing that in .idea project files but it just reappears after IDE restart. Any suggestions? [build.gradle.xml](https://discuss.kotlinlang.org/uploads/short-url/sQket68Xeasoer0MqkPpr1cmUtQ.xml) (3.1 KB)

---

<div class="post-metadata">

**Author:** ![leonid](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@leonid](https://discuss.kotlinlang.org/u/leonid)\
**Post date:** [December 17, 2018, 7:46am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/116 "2018-12-17T07:46:02Z")

</div>

It would be good to have, or may it already exist, an example for new mpp model, like kotlin-fullstack-example [ktor 0.9.0 · Issue #27 · Kotlin/kotlin-fullstack-sample · GitHub](https://github.com/Kotlin/kotlin-fullstack-sample/issues/27)

---

<div class="post-metadata">

**Author:** ![wild\_lynx](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wild_lynx/32/6767_2.png) [@wild\_lynx](https://discuss.kotlinlang.org/u/wild_lynx)\
**Post date:** [December 17, 2018, 10:53am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/117 "2018-12-17T10:53:29Z")

</div>

Please make sure in IDE that _Preferences | Build, Execution, Deployment | Build Tools | Gradle | Runner_ \> _Delegate IDE build/run actions to gradle_ is **checked**. For the IDEA’s built-in builder (JPS), there is [an issue](https://youtrack.jetbrains.com/issue/KT-28861). Does it help?

Also please note that in general, Gradle is a preferred way to build the multiplatform projects; JPS has certain limitations (in particular, it wouldn’t build any of Native targets, such as iOS in your project).

A small comment on the `build.gradle` you’ve shared: for the source sets generated from the presets (`jvm`, `js`, etc.), it isn’t necessary to specify explicitly the dependencies of the corresponding `*Main` and `*Test` compilations on `commonMain` and `commonTest` explicitly, those are specified already by default, as it said at [the documentation](http://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#default-project-layout). So the following line of your configuration for `serverMain` may be simply removed: `dependsOn commonMain`

---

<div class="post-metadata">

**Author:** ![wild\_lynx](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wild_lynx/32/6767_2.png) [@wild\_lynx](https://discuss.kotlinlang.org/u/wild_lynx)\
**Post date:** [December 17, 2018, 10:57am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/118 "2018-12-17T10:57:52Z")

</div>

Indeed, there are some already. You may try various samples generated by IDEA via New Project Wizard: open Kotlin section, there are four of them (Multiplatform).

Also, please have a look:  
• [GitHub - orangy/multiplatform-lib: Sample multiplatform library in Kotlin with tests and publishing](https://github.com/orangy/multiplatform-lib)  
• [GitHub - h0tk3y/better-parse: A nice parser combinator library for Kotlin](https://github.com/h0tk3y/better-parse)  
• [GitHub - Kotlin/kotlinx.atomicfu: The idiomatic way to use atomic operations in Kotlin](https://github.com/Kotlin/kotlinx.atomicfu)  
• [GitHub - Kotlin/kmm-basic-sample: Example of Kotlin multiplatform project](https://github.com/JetBrains/kotlin-mpp-example)  
• [GitHub - JetBrains/kotlinconf-app: KotlinConf Schedule Application](https://github.com/JetBrains/kotlinconf-app)  
• [GitHub - jonnyzzz/kotlin-fractals](https://github.com/jonnyzzz/kotlin-fractals)  
• [GitHub - jonnyzzz/kotlin-mpp-mobile](https://github.com/jonnyzzz/kotlin-mpp-mobile)  
• [GitHub - RubyLichtenstein/Kotlin-Multiplatform-Firebase: Kotlin Multiplatform - Android/iOS/Web/Node.Js(FIrebase)](https://github.com/RubyLichtenstein/Kotlin-Multiplatform-Firebase)

---

<div class="post-metadata">

**Author:** ![marco89nish](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@marco89nish](https://discuss.kotlinlang.org/u/marco89nish)\
**Post date:** [December 17, 2018, 8:46pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/119 "2018-12-17T20:46:53Z")

</div>

Thanks, offloading build to gradle fixed the build issues. Btw, should jvm server be runnable from IDEA now? Cause I’m having troubles just running hello world server, I get this error: `Error: Could not find or load main class rs.mmitic.MainKt`

It’s possible that I’m just a dummy, I haven’t coded in Kotlin that much but I’ve tried lots of stuff:

```
package rs.mmitic
import sample.hello

object Main {
    @JvmStatic
    fun main(args: Array<String>) {
        print(hello())
    }
}

class Main2 {
    companion object {
        @JvmStatic
        fun main(vararg args: String) {}
    }
}

fun main(args: Array<String>) {
    print(hello())
}

```

---

<div class="post-metadata">

**Author:** ![wild\_lynx](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wild_lynx/32/6767_2.png) [@wild\_lynx](https://discuss.kotlinlang.org/u/wild_lynx)\
**Post date:** [December 18, 2018, 3:24pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/120 "2018-12-18T15:24:46Z")

</div>

There is [an issue](https://youtrack.jetbrains.com/issue/KT-26885) with `main` run in IDEA for the multiplatform projects having `Android` target among others.

As a workaround, a Gradle task for the `main` run may be specified:

```
task run(type: JavaExec) {
    main = 'sample.SampleJKt'
    def target = kotlin.targets.jvm
    def compilation = target.compilations.main

    def classes = files(
            compilation.runtimeDependencyFiles,
            compilation.output.allOutputs
    )
    classpath = classes
}

```

— where `main` is a path to the class with `main()` function defined as follows:

- if `main` is declared as a top-level function, then _packageName + “.” + fileName.capitalized().removeSuffix(“.kt”) + “Kt”_
- if `main` is declared inside of an `object`, then _packageName + “.” + objectName_

For a file without package, for example, `ActualB.kt`: `main = 'ActualBKt'`

---

<div class="post-metadata">

**Author:** ![marco89nish](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@marco89nish](https://discuss.kotlinlang.org/u/marco89nish)\
**Post date:** [December 18, 2018, 3:42pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/121 "2018-12-18T15:42:28Z")

</div>

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Egorand](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/egorand/32/5897_2.png) [@Egorand](https://discuss.kotlinlang.org/u/Egorand)\
**Post date:** [December 22, 2018, 11:43pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/122 "2018-12-22T23:43:48Z")

</div>

Is it going to be the only way to work around the absence of `jvmWithJava`? In Okio, we’ve got unit tests written in Java living in the JVM module: their main value is that they test the API from the perspective of a Java user of the library and help us keep the API Java-friendly. Some unit tests rely on `internal` members, hence moving them into a separate module is not an option. Inability to compile and run Java code in the JVM module is pretty inconvenient and will require a lot of redesign on our part.

---

<div class="post-metadata">

**Author:** ![h0tk3y](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/h0tk3y/32/1781_2.png) [@h0tk3y](https://discuss.kotlinlang.org/u/h0tk3y)\
**Post date:** [December 25, 2018, 11:12am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/123 "2018-12-25T11:12:21Z")

</div>

@Egorand Yes, for now. But we are going to introduce Java support in the future releases, in some form. From what I can say now, it will likely be something quite similar to `jvmWithJava`, because applying the `java` Gradle plugin seems to be the only way to reach compatibility with existing 3rd-party plugins that work with Java. So if you try to use `jvmWithJava`, then your feedback is welcome. The issue for Java support that you can follow is: [KT-26256](https://youtrack.jetbrains.com/issue/KT-26256).

---

<div class="post-metadata">

**Author:** ![Egorand](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/egorand/32/5897_2.png) [@Egorand](https://discuss.kotlinlang.org/u/Egorand)\
**Post date:** [December 25, 2018, 1:51pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/124 "2018-12-25T13:51:53Z")

</div>

Thanks! Here’s an issue I filed a couple days ago: [https://youtrack.jetbrains.com/issue/KT-28985](https://youtrack.jetbrains.com/issue/KT-28985)

---

<div class="post-metadata">

**Author:** ![Egorand](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/egorand/32/5897_2.png) [@Egorand](https://discuss.kotlinlang.org/u/Egorand)\
**Post date:** [December 26, 2018, 6:30pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/125 "2018-12-26T18:30:21Z")

</div>

Doesn’t look like the plugin plays well with Dokka, and it’s not mentioned on the official docs page. Is Dokka gonna be supported eventually?

[Previous page](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264.md?page=5)

[Next page](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264.md?page=7)
