# 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:** 5

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [October 26, 2018, 1:25pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/86 "2018-10-26T13:25:34Z")

</div>

Is this solution possible in the last version? Last time I’ve checked I could not depend on multiplaftorm module from simple koltin module.

---

<div class="post-metadata">

**Author:** ![zzmingo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/zzmingo/32/5682_2.png) [@zzmingo](https://discuss.kotlinlang.org/u/zzmingo)\
**Post date:** [October 26, 2018, 1:49pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/87 "2018-10-26T13:49:55Z")

</div>

How can I use kapt in `kotlin-multiplatform` project ? from kapt document and example, I figure out following steps:

include “:kapt” in settings.gradle  
apply plugin ‘kotlin-kapt’ in build.gradle  
add deps in sourceSets.commonMain

but i got this error: Could not find method kapt() for arguments [project ‘:xxxx’]

---

<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:** [October 26, 2018, 2:07pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/88 "2018-10-26T14:07:47Z")

</div>

@darksnake Yes, it should work. Here’s a minimal sample:

[jmv-depends-on-mpp.zip](https://discuss.kotlinlang.org/uploads/short-url/7CtfAWAdLtA546Lb4JQdFgcJEGK.zip) (53.0 KB)

If it doesn’t work for you, please let us know what goes wrong, or report an issue at [https://kotl.in/issue](https://kotl.in/issue).

---

<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:** [October 26, 2018, 2:13pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/89 "2018-10-26T14:13:15Z")

</div>

@zzmingo You should add the Kapt dependencies at the top level in a `dependencies { ... }` block, not in the `kotlin { sourceSets { ... } }` DSL. Also, at this point, Kapt is expected to work with Android targets in multiplatform projects, but not with JVM ones which are created with `presets.jvm` since it does not compile Java. If you need Kapt for a non-Android project, you can try to use `presets.jvmWithJava`, but please note that this preset is going to be replaced with another form of Java support, as @wild_lynx described above.

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.

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [October 26, 2018, 2:32pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/90 "2018-10-26T14:32:11Z")

</div>

It seems to be working with IDEA, but gradle gives me this:

```auto
Could not resolve project :kmath-core.
     Required by:
         project :kmath-jmh
Cannot choose between the following variants of project :kmath-core:
  - jvmRuntimeElements
  - runtimeElements
All of them match the consumer attributes:
  - Variant 'jvmRuntimeElements':
      - Found org.gradle.usage 'java-runtime-jars' but wasn't required.
      - Required org.jetbrains.kotlin.localToProject ':kmath-jmh' but no value provided.
      - Required org.jetbrains.kotlin.platform.type 'jvm' and found compatible value 'jvm'.
  - Variant 'runtimeElements':
      - Found org.gradle.usage 'java-runtime-jars' but wasn't required.
      - Required org.jetbrains.kotlin.localToProject ':kmath-jmh' but no value provided.
      - Required org.jetbrains.kotlin.platform.type 'jvm' but no value provided.

```

---

<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:** [October 26, 2018, 2:37pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/91 "2018-10-26T14:37:04Z")

</div>

@darksnake Which plugins do you apply in the `:kmath-core` project? It looks like the ambiguity is caused by a configuration `runtimeElements` created by the `java` plugin. This may happen if you apply one of the `java` and `kotlin` plugins along with `kotlin-multiplatform`.

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [October 26, 2018, 2:44pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/92 "2018-10-26T14:44:47Z")

</div>

You are correct! Thank you very much for suggestion I found that I forgot to remove jmh plugin from core. Now it works properly. Great news indeed!

The only problem left is that for some reason IDEA generates gradle root project configuration for each module. It does not affect build, but is a bit annoying.

---

<div class="post-metadata">

**Author:** ![zzmingo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/zzmingo/32/5682_2.png) [@zzmingo](https://discuss.kotlinlang.org/u/zzmingo)\
**Post date:** [October 26, 2018, 3:28pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/93 "2018-10-26T15:28:19Z")

</div>

It’s working now by adding into top-level deps.  
As you said, seems it’s only working with java or jvmWithJava module, can I use it in a platform-common module?

---

<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:** [October 26, 2018, 3:34pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/94 "2018-10-26T15:34:01Z")

</div>

@zzmingo Note that, as most annotation processors work by generating Java, using Kapt for other platforms than JVM doesn’t make much sense (at least unless you somehow compile the generated Java sources for those platforms as well, which is not possible out-of-the-box). So I’m just not quite sure I understand how exactly you want to use Kapt on common sources. Could you please describe the overall structure of your project?

---

<div class="post-metadata">

**Author:** ![zzmingo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/zzmingo/32/5682_2.png) [@zzmingo](https://discuss.kotlinlang.org/u/zzmingo)\
**Post date:** [October 26, 2018, 3:51pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/95 "2018-10-26T15:51:58Z")

</div>

@h0tk3y So far, the project structure is very simple and it created by IDEA kotlin plugin with “Kotlin (Mobile Shared Library)”.  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/5/5aac091d28d46ec6b851a6321c179d6445ad9d85.jpeg)

The module kapt contains compiler sources and aim to analysis sources of commonMain to generating some extensions of kotlin data class.

For example, decalare a class in commonMain named `model.kt`

```kotlin
@GeneratedMyExtension
data class Model(var name: String)

```

I hope there is a extension file auto generated, look like this:

```kotlin
fun Model.displayName() = "My name is $name"

```

---

<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:** [October 29, 2018, 3:06am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/96 "2018-10-29T03:06:21Z")

</div>

> [@darksnake](#):
>
> The only problem left is that for some reason IDEA generates gradle root project configuration for each module. It does not affect build, but is a bit annoying.

Do you mean, IDEA adds some configuration, specific to a root project only (like `settings.gradle` file), every time you add a new multiplatform module into an existing project?

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [October 29, 2018, 4:54am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/97 "2018-10-29T04:54:14Z")

</div>

Something like that. I had normal root configuration and idea root gradle configurations for each of modules, so I had several separate trees in gradle sync window. I solved the problem by removing those phantom roots manually, they do not reappear on sync. I don’t remember how I added modules in the first place. Maybe it was the problem of module wizard in IDEA. I will report back if the problem reappears.

---

<div class="post-metadata">

**Author:** ![zzmingo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/zzmingo/32/5682_2.png) [@zzmingo](https://discuss.kotlinlang.org/u/zzmingo)\
**Post date:** [November 1, 2018, 9:33am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/98 "2018-11-01T09:33:54Z")

</div>

When using new mpp with version `1.3.0-rc-190` and coroutine `1.0.0`, I got this fail to compile iOS:

```auto
warning: skipping ....gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/
kotlinx-coroutines-core-native_debug_ios_arm64/1.0.0/7ca0a37e5dca2e6edf4e605f87c8ea5e92d3ef77/
kotlinx-coroutines-core-native.klib. 
The compiler versions don't match. Expected '[0.9.3]', found '1.0.1-release-4583'

```

I am afraid I can’t fix it by myself.

---

<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 8, 2018, 11:58am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/99 "2018-11-08T11:58:49Z")

</div>

Please, update the versions to the compatible ones: `1.0.1` for `kotlinx.coroutines` and `1.3.0` for Kotlin. Did it help?

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [November 8, 2018, 5:56pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/100 "2018-11-08T17:56:50Z")

</div>

I have very bizarre behavior for MPP project with several modules (let’s call them `m1` and `m2`). When I import in `m2`-common some classes from file in `m1`-common everything is working fine as long as I use separate imports for each class. But if I use star import (which is done automatically by IDE), gradle build fails with Unresolved reference.

I searched the tracker and found a lot of different errors which are mostly fixed in 1.3.20. Is this a known problem?

---

<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 9, 2018, 9:20am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/101 "2018-11-09T09:20:49Z")

</div>

I didn’t recognize it as a known issue from the first glance, so can you please either share `build.gradle` configurations for the project and its modules here or in a new YT issue?  
The only guess so far is that there are same-named packages in both modules and there is an ambiguity in the mapping of platform-specific source sets between `m1` and `m2` modules

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [November 9, 2018, 9:28am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/102 "2018-11-09T09:28:51Z")

</div>

The project is [here](https://github.com/altavir/dataforge-core/tree/dev). And the build fails in [MetaFormat](https://github.com/altavir/dataforge-core/blob/dev/dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/MetaFormat.kt) class.The package name is not the same. In the library module it is `hep.dataforge.meta` and in io module it is `hep.dataforge.meta.io`. I will open a ticket later.

---

<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 14, 2018, 11:15pm UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/103 "2018-11-14T23:15:26Z")

</div>

is it possible to use plugins in presets or ir it can be done some other way? for example shadow(fat jar) for jvm or kotlin-frontend for js? does anyone have working example?

---

<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:27am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/104 "2018-11-15T06:27:40Z")

</div>

I’m working on a multi-platform project, currently Android and JS (client), and am trying to copy additional files as part of the Gradle build.

```

kotlin {
  targets {
    fromPreset(presets.android, 'android') {
      compilations.all {
        tasks[compileKotlinTaskName].dependsOn syncAndroidAssets
      }
    }

    fromPreset(presets.js, 'js') {
      compilations.all {
        tasks[compileKotlinTaskName].dependsOn syncJsAssets, syncJsHtml
      }
    }
  }

  sourceSets {
    // ....
  }

```

Where “sync[Name]” are my custom tasks.The JS target works great, but the Android target fails with

> Task with name ‘compileDebugKotlinAndroid’ not found in project

Is this just not working, or should be done in a different way?

---

<div class="post-metadata">

**Author:** ![msink](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/msink/32/3336_2.png) [@msink](https://discuss.kotlinlang.org/u/msink)\
**Post date:** [November 15, 2018, 6:46am UTC](https://discuss.kotlinlang.org/t/kotlin-1-3-m2-new-multiplatform-projects-model/9264/105 "2018-11-15T06:46:17Z")

</div>

```auto
tasks.compileKotlinNative.dependsOn compileWindowsResources

```

works for Kotlin/Native.

Maybe for you case something like this will work:

```auto
tasks.compileKotlinAndroid.dependsOn syncAndroidAssets

```

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

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