xref: /aosp_15_r20/external/kotlinx.serialization/docs/building.md (revision 57b5a4a64c534cf7f27ac9427ceab07f3d8ed3d8)
1# Building Kotlin Serialization from the source
2
3## JDK version
4
5To build Kotlin Serialization JDK version 11 or higher is required. Make sure this is your default JDK (`JAVA_HOME` is set accordingly).
6This is needed to compile the `module-info` file included for JPMS support.
7
8In case you are determined to use different JDK version, or experience problems with JPMS you can turn off compilation of modules
9completely with `disableJPMS` property: add `disableJPMS=true` to gradle.properties or `-PdisableJPMS` to Gradle CLI invocation.
10
11## Runtime library
12
13Kotlin Serialization runtime library itself is a [multiplatform](http://kotlinlang.org/docs/reference/multiplatform.html) project.
14To build library from the source and run all tests, use `./gradlew build`. Corresponding platform tasks like `jvmTest`, `jsTest`, `nativeTest` and so on are also available.
15
16Project can be opened in in Intellij IDEA without additional prerequisites.
17In case you want to work with Protobuf tests, you may need to run `./gradlew generateTestProto` beforehand.
18
19
20To install runtime library into the local Maven repository, run `./gradlew publishToMavenLocal`.
21After that, you can include this library in arbitrary projects like usual gradle dependency:
22
23```gradle
24repositories {
25    mavenLocal()
26}
27
28dependencies {
29    compile "org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version"
30}
31```
32
33Note that by default, only one Native target is built (the one that is the current host, e.g. `macosX64` on Intel Mac machines, `linuxX64` on linux machines, etc).
34To compile and publish all Native artifacts, not only the host one, use Gradle property `native.deploy=true`.
35
36To use snapshot version of compiler (if you have built and install it from sources), use flag `-Pbootstrap`.
37If you have built both Kotlin and Kotlin/Native compilers, set `KONAN_LOCAL_DIST` environment property to the path with Kotlin/Native distribution
38(usually `kotlin-native/dist` folder inside Kotlin project).
39
40`master` and `dev` branches of library should be binary compatible with latest released compiler plugin. In case you want to test some new features from other branches,
41which are still in development and may not be compatible in terms of bytecode produced by plugin, you'll need to build the plugin by yourself.
42
43## Compiler plugin
44
45Compiler plugin for Gradle/Maven and IntelliJ plugin, starting from Kotlin 1.3, are embedded into the Kotlin compiler.
46
47Sources and steps to build it are located [here](https://github.com/JetBrains/kotlin/tree/master/plugins/kotlinx-serialization).
48In short, you'll just need to run `./gradlew dist install` to get `1.x.255-SNAPSHOT` versions of Kotlin compiler, stdlib and serialization plugins in the Maven local repository.
49