You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/topics/gradle/gradle-configure-project.md
+96-4Lines changed: 96 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -635,9 +635,68 @@ Learn more about [Kotlin Multiplatform for different platforms](https://www.jetb
635
635
636
636
It's recommended to use Android Studio for creating Android applications. [Learn how to use the Android Gradle plugin](https://developer.android.com/studio/releases/gradle-plugin).
637
637
638
-
## Targeting JavaScript
638
+
## Targeting the web
639
639
640
-
When targeting JavaScript, use the `kotlin-multiplatform` plugin as well. [Learn more about setting up a Kotlin/JS project](js-project-setup.md)
640
+
Kotlin, through Kotlin Multiplatform, offers two approaches for web development:
641
+
642
+
* JavaScript-based (using the Kotlin/JS compiler)
643
+
* WebAssembly-based (using the Kotlin/Wasm compiler)
644
+
645
+
Both approaches use the Kotlin Multiplatform plugin but support different use cases.
646
+
The sections below explain how to configure each target in your Gradle build and when to use them.
647
+
648
+
### Targeting JavaScript
649
+
650
+
Use Kotlin/JS if your goal is to:
651
+
652
+
* Share business logic with a JavaScript/TypeScript codebase
653
+
* Build non-shareable web apps with Kotlin
654
+
655
+
For more information, see [Choose the right web target for a Kotlin Multiplatform project](https://www.jetbrains.com/help/kotlin-multiplatform-dev/choosing-web-target.html).
656
+
657
+
When targeting JavaScript, use the `kotlin-multiplatform` plugin:
658
+
659
+
<tabs group="build-script">
660
+
<tab title="Kotlin" group-key="kotlin">
661
+
662
+
```kotlin
663
+
plugins {
664
+
kotlin("multiplatform") version "%kotlinVersion%"
665
+
}
666
+
```
667
+
668
+
</tab>
669
+
<tab title="Groovy" group-key="groovy">
670
+
671
+
```groovy
672
+
plugins {
673
+
id 'org.jetbrains.kotlin.multiplatform' version '%kotlinVersion%'
674
+
}
675
+
```
676
+
677
+
</tab>
678
+
</tabs>
679
+
680
+
Configure the JavaScript target by specifying whether it should run in the browser or the Node.js environment:
681
+
682
+
```kotlin
683
+
kotlin {
684
+
js().browser { // or js().nodejs
685
+
/* ... */
686
+
}
687
+
}
688
+
```
689
+
690
+
> See [further details about the Gradle configuration for JavaScript](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-dsl-reference.html#web-targets) and learn more about [setting up a Kotlin/JS project](js-project-setup.md).
691
+
>
692
+
{style="note"}
693
+
694
+
### Targeting WebAssembly
695
+
696
+
Use Kotlin/Wasm if you want to share both logic and UI across multiple platforms. For more information,
697
+
see [Choose the right web target for a Kotlin Multiplatform project](https://www.jetbrains.com/help/kotlin-multiplatform-dev/choosing-web-target.html).
698
+
699
+
As with JavaScript, use the `kotlin-multiplatform` plugin when targeting WebAssembly (Wasm):
641
700
642
701
<tabs group="build-script">
643
702
<tab title="Kotlin" group-key="kotlin">
@@ -660,9 +719,42 @@ plugins {
660
719
</tab>
661
720
</tabs>
662
721
663
-
### Kotlin and Java sources for JavaScript
722
+
Depending on your requirements, you can target:
723
+
724
+
* **`wasmJs`**: for running in browsers or Node.js
725
+
* **`wasmWasi`**: for running in Wasm environments supporting [WASI (WebAssembly System Interface)](https://wasi.dev/), such as Wasmtime, WasmEdge, and so on.
726
+
727
+
Configure the `wasmJs` target for web browsers or Node.js:
728
+
729
+
```kotlin
730
+
kotlin {
731
+
wasmJs {
732
+
browser { // or nodejs
733
+
/* ... */
734
+
}
735
+
}
736
+
}
737
+
```
738
+
739
+
For WASI environments, configure the `wasmWasi` target:
740
+
741
+
```kotlin
742
+
kotlin {
743
+
wasmWasi {
744
+
nodejs {
745
+
/* ... */
746
+
}
747
+
}
748
+
}
749
+
```
750
+
751
+
> [See further details about the Gradle configuration for Wasm](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-dsl-reference.html#web-targets).
752
+
>
753
+
{style="note"}
754
+
755
+
### Kotlin and Java sources for the web target
664
756
665
-
This plugin only works for Kotlin files, so it is recommended that you keep Kotlin and Java files separate (if the
757
+
The KGP only works for Kotlin files, so it is recommended that you keep Kotlin and Java files separate (if the
666
758
project contains Java files). If you don't store them separately, specify the source folder in the `sourceSets{}` block:
0 commit comments