# JsName and JVMName cannot be used in the same project

**URL:** <https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506>\
**Category:** Language Design\
**Created:** [July 10, 2018, 7:18am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506 "2018-07-10T07:18:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleks.p.petrov](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@aleks.p.petrov](https://discuss.kotlinlang.org/u/aleks.p.petrov)\
**Post date:** [July 10, 2018, 7:18am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/1 "2018-07-10T07:18:16Z")

</div>

I am trying to create a library that can both be compiled into jar file for an Android project and transpiled to JavaScript for a Node.js project.

The code is exactly the same for both platforms and has no platform specific parts. Therefor, I don’t want to split it in common and platform specific code and I don’t want to create custom interfaces (facades) for each platform.

The problem is that a lot of the names get mangled. I know about the @JsName and @JVMName annotations, but they are not compatible with each other and:

- kotlin plugin doesn’t understand @JVMName;
- kotlin2js plugin doesn’t understand @JsName.

I searched for a solution but didn’t find a good one.

I hope you can help me!

Best Regards,  
Alex

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [July 10, 2018, 8:28am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/2 "2018-07-10T08:28:00Z")

</div>

You will have to create a normal multi-platform project. Just put all your code into the common project. You still have to create a js and android module, but you don’t have to add any code to it. Just make sure that the build file is set up correctly.  
If you later need any platform specific code you can just add it to the platform modules and add `expect` functions to the common module.

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [July 10, 2018, 8:32am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/3 "2018-07-10T08:32:49Z")

</div>

Woops. Now that I said that, there is still one problem, but it should be fixed in 1.2.60 I think, not sure  
see here for more info:

> [@JsName annotation in common code for multiplatform projects](https://discuss.kotlinlang.org/t/jsname-annotation-in-common-code-for-multiplatform-projects/5913):
>
> Hello, We are trying to build a library to be shared between Java and JS. Behaviour of lib is to be extended in apps which will be using this lib (including in JS). Because of that I want to controll js naming in common code, which is now impossible. I saw there was a [discussion](https://discuss.kotlinlang.org/t/jsname-annotation-for-shared-code/2623), but it was abandoned 6 month ago. Consider following example (simplified): interface Processor { fun doProcess(businessObject: BusinessObject, dataProvider: DataProvider): OperationResult } data class Busines…

[https://youtrack.jetbrains.com/issue/KT-18882](https://youtrack.jetbrains.com/issue/KT-18882)  
[https://youtrack.jetbrains.com/issue/KT-24478](https://youtrack.jetbrains.com/issue/KT-24478)

---

<div class="post-metadata">

**Author:** ![aleks.p.petrov](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@aleks.p.petrov](https://discuss.kotlinlang.org/u/aleks.p.petrov)\
**Post date:** [July 11, 2018, 7:50am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/4 "2018-07-11T07:50:12Z")

</div>

@Wasabi375, thank you for the reply! I have already checked the ticket mentioned by you. The fact that it is not yet present and nobody confirmed that it will be is concerning for me and is the reason to post my ticket.

Anyway, thanks again for the quick reply and lets hope they add JsName in the common library

---

<div class="post-metadata">

**Author:** ![aleks.p.petrov](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@aleks.p.petrov](https://discuss.kotlinlang.org/u/aleks.p.petrov)\
**Post date:** [July 11, 2018, 10:59am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/5 "2018-07-11T10:59:10Z")

</div>

I just tried the early access preview of Kotlin v1.2.60, as described in this post:

> [@Kotlin 1.2.60 Early Access Preview](https://discuss.kotlinlang.org/t/kotlin-1-2-60-early-access-preview/8282):
>
> We’re happy to announce the Early Access Preview (EAP) build for Kotlin 1.2.60! What’s new The full changelog is available [here](https://github.com/JetBrains/kotlin/releases/tag/v1.2.60-eap-7). How to get the EAP build For IntelliJ IDEA You can configure Early Access Preview channel in Tools → Kotlin → Configure Kotlin Plugin Updates. Change the update channel to ‘Early Access Preview 1.2.x’ and press Check for updates now. For Maven or Gradle Add the https://dl.bintray.com/kotlin/kotlin-eap repository URL to the list of project repositories. Here is h…

And the JsName annotation is not added in the common library.

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [July 11, 2018, 11:13am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/6 "2018-07-11T11:13:08Z")

</div>

Woops, looks like only one of the 2 tickets is part of 1.2.6. Looks like [KT-24478](https://youtrack.jetbrains.com/issue/KT-24478) has no target version yet. My bad.

---

<div class="post-metadata">

**Author:** ![udalov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/udalov/32/5679_2.png) [@udalov](https://discuss.kotlinlang.org/u/udalov)\
**Post date:** [July 11, 2018, 11:13am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/7 "2018-07-11T11:13:45Z")

</div>

To clarify, in 1.2.60 we introduced a mechanism to declare such annotations in common code, so that they would be available on platforms (`@OptionalExpectation`, described in [KT-18882](https://youtrack.jetbrains.com/issue/KT-18882)). We did not yet add all relevant annotations to the common standard library. This requires more changes, which will (unfortunately) likely not make it into 1.2.60. They are tracked under [KT-24478](https://youtrack.jetbrains.com/issue/KT-24478).

---

<div class="post-metadata">

**Author:** ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)\
**Post date:** [July 12, 2018, 5:15am UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/8 "2018-07-12T05:15:55Z")

</div>

You can of course create your own expect annotations that are typealiased to the platform ones on the platform or implemented as (source only) dummies on platforms that don’t have that annotation. It works (even on 1.2.51) with some limitations - first of which is that intellij doesn’t like it (there are still numerous multiplatform limitations in intellij). If you are happy to ignore warnings you can even use the EAP plugin in intellij while targeting 1.2.51.

---

<div class="post-metadata">

**Author:** ![aleks.p.petrov](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@aleks.p.petrov](https://discuss.kotlinlang.org/u/aleks.p.petrov)\
**Post date:** [November 20, 2018, 12:01pm UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/9 "2018-11-20T12:01:11Z")

</div>

Any update on this topic? I don’t see any resolution yet.

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [December 4, 2018, 11:50pm UTC](https://discuss.kotlinlang.org/t/jsname-and-jvmname-cannot-be-used-in-the-same-project/8506/10 "2018-12-04T23:50:32Z")

</div>

@aleks.p.petrov Since Kotlin 1.2.70 you can use both `JsName` and `JvmName` annotations in common code.

However you can’t just take that code and compile it twice — for JS and JVM, you need to structure it as a multiplatform project, that distinguishes common and platform specific code. You can read more about the current approach to authoring multiplatform projects here:  
[https://kotlinlang.org/docs/reference/multiplatform.html](https://kotlinlang.org/docs/reference/multiplatform.html)  
[https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html)
