diving into kotlin multiplatform dimitry savvinov
play

Diving into Kotlin Multiplatform Dimitry Savvinov @dsavvinov - PowerPoint PPT Presentation

Kotlin 1.4 Online Event Diving into Kotlin Multiplatform Dimitry Savvinov @dsavvinov October 14, 2020 Disclaimer A lot of internals ahead: Information is this talk might become outdated in the future The actual documentation is


  1. Kotlin 1.4 Online Event Diving into Kotlin Multiplatform Dimitry Savvinov @dsavvinov October 14, 2020

  2. Disclaimer A lot of internals ahead: Information is this talk might ● become outdated in the future The actual documentation ● is the only source of truth Some parts are totally internal ● (will be marked so explicitly)

  3. 1.4 MPP The story of one feature

  4. 1.3 Two levels of hierarchy common jvm js linux macos

  5. 1.4 Multiple levels of hierarchy common jvmAndJs native jvm js linux macos

  6. Multiplatform Publishing

  7. Publishing repo common jvmAndJs native jvm js linux macos

  8. Publishing repo common jvmAndJs native jvm js linux macos In 1.3 intermediate source sets are not published

  9. Publishing repo common jvmAndJs native jvm js linux macos In 1.4 all source sets are published

  10. Why do we need intermediate source sets to be published? Your project Library you depend on common common jvm js linux macos macos linux js jvm

  11. Why do we need intermediate source sets to be published? Your project Library you depend on common common native native jvm js linux macos macos linux js jvm

  12. Kotlin Publishing Model in a nutshell common Kotlin tries to reuse as jvmAndJs native much of the platform ecosystem as possible jvm js linux macos JAR and JAR ... classfiles and .js

  13. Kotlin Publishing Model in a nutshell common ??? jvmAndJs native jvm js linux macos JAR and JAR ... classfiles and .js

  14. Kotlin Publishing Model in a nutshell JAR  common .kotlin_metadata jvmAndJs native jvm js linux macos JAR and JAR ... classfiles and .js

  15. Experiments section: publishing in 1.3

  16. How I can play with a published library? 1. build.gradle settings.gradle plugins { rootProject.name = '<project-name>' id ‘maven-publish’ } group = '<group.id>' version = '<my-version>' 2. $ ./gradlew publishToMavenLocal 3. $ cd ~/.m2/repository/<group>/<id>/<project-name>

  17. Example: MPP Library in 1.3 ➜ mpp pwd /Users/dmitry.savvinov/.m2/repository/hello/mpp Auxiliary artifact ➜ mpp tree -L 1 (we’ll get to it later) ├── my-mpp-lib ├── my-mpp-lib-js JS part published as .jar │ └── 1.0-SNAPSHOT (.js files inside) │ └── my-mpp-lib-js-1.0-SNAPSHOT.jar ├── my-mpp-lib-jvm JVM part published as .jar │ └── 1.0-SNAPSHOT (.classfiles inside) │ └── my-mpp-lib-jvm-1.0-SNAPSHOT.jar ├── my-mpp-lib-macosx64 Kotlin/Native part │ └── 1.0-SNAPSHOT published as .klib │ └── my-mpp-lib-macosx64-1.0-SNAPSHOT.klib └── my-mpp-lib-metadata └── 1.0-SNAPSHOT Common part published as .jar └── my-mpp-lib-metadata-1.0-SNAPSHOT.jar

  18. How can I peek into .kotlin_metadata? 1. Publish it into a maven local as described in the previous steps 2. Create a stub-project and add a dependency from it on a published library: build.gradle repositories { ... mavenLocal() } ... sourceSets { commonMain { dependencies { implementation '<group>.<id>:<project-name>:<version>' } } ... } 3. Open in the IDE and see “Externals Libraries” in the “Project Structure”

  19. You can even browse the common part of stdlib! // IntelliJ API Decompiler stub source generated from a class file // Implementation of methods is not available package kotlin public final class String public constructor() : kotlin.Comparable<kotlin.String>, kotlin.CharSequence { public companion object { } public open val length: kotlin.Int /* compiled code */ public open operator fun compareTo(other: kotlin.String): kotlin.Int { /* compiled code */ } public open operator fun equals(other: kotlin.Any?): kotlin.Boolean { /* compiled code */ } public open operator fun get(index: kotlin.Int): kotlin.Char { /* compiled code */ } public open fun hashCode(): kotlin.Int { /* compiled code */ } ...

  20. 1.4 Publishing intermediate source sets JAR  common .kotlin_metadata Should be compiled jvmAndJs native by K/N compiler K/N compiler doesn’t know how to work jvm js linux macos with .kotlin_metadata JAR and JAR ... classfiles and .js

  21. 1.4 Publishing everything into klibs Common denominator ● klib common klib common klib across all backends klib Can be easily ● evolved further jvmAndJs native jvmAndJs native jvm js linux macos jvm js linux macos * experimental, under explicit opt-in JAR and JAR and klib klib ** in the future classfiles .js or klib* or klib**

  22. Experiments section: publishing in 1.4

  23. Publish an MPP library in a new format 1. build.gradle settings.gradle plugins { rootProject.name = '<project-name>' id ‘maven-publish’ } kotlin.mpp.enableGranularSourceSetsMetadata=true group = '<group.id>' version = '<my-version>' 2. $ ./gradlew publishToMavenLocal 3. $ cd ~/.m2/repository/<group>/<id>/<project-name>

  24. Example: MPP Library in 1.4 ➜ mpp pwd /Users/dmitry.savvinov/.m2/repository/hello/mpp ➜ mpp tree -L 1 ├── my-mpp-lib ├── my-mpp-lib-js │ └── 1.0-SNAPSHOT │ └── my-mpp-lib-js-1.0-SNAPSHOT.jar ├── my-mpp-lib-jvm │ └── 1.0-SNAPSHOT │ └── my-mpp-lib-jvm-1.0-SNAPSHOT.jar ├── my-mpp-lib-macosx64 │ └── 1.0-SNAPSHOT │ └── my-mpp-lib-macosx64-1.0-SNAPSHOT.klib └── my-mpp-lib-metadata └── 1.0-SNAPSHOT Common part published as .klib └── my-mpp-lib-metadata-1.0-SNAPSHOT. klib

  25. A peek into klibs .klib extension packaged as .zip Reserved multiple variants for better compatibility in the future Bodies are stored in an internal format called IR .kotlin_metadata is still present for the sake of tooling Key-value manifest for internal purposes

  26. Dependencies management

  27. Dependencies management 1.3 1.4 sourceSets.commonMain.dependencies { implementation ‘my-library-common’ } sourceSets.jvmMain.dependencies { sourceSets.commonMain.dependencies { implementation ‘my-library-jvm’ implementation ‘my-library’ } } sourceSets.jsMain.dependencies { implementation ‘my-library-js’ }

  28. Simple case Your project Library you depend on common common jvm js linux macos macos linux js jvm

  29. Not So Simple case Your project Library you depend on common common allExceptJvm allExceptJs jvm js linux macos drawin macos iOS linux js jvm

  30. What are we even supposed to do? common allExceptJvm allExceptJs ??? JVM drawin macos iOS linux js jvm

  31. What are we even supposed to do? common allExceptJvm allExceptJs JVM drawin macos iOS linux js jvm

  32. What are we even supposed to do? common allExceptJvm allExceptJs JVM ??? drawin Windows macos iOS linux js jvm

  33. What are we even supposed to do? common allExceptJvm allExceptJs JVM drawin Windows macos iOS linux js jvm

  34. What are we even supposed to do? common LinuxAndJS ??? allExceptJvm allExceptJs JVM drawin Windows macos iOS linux js jvm

  35. What are we even supposed to do? common LinuxAndJS allExceptJvm allExceptJs JVM drawin Windows macos iOS linux js jvm

  36. What are we even supposed to do? data class Platform(val components: Set<SimplePlatform>) enum class SimplePlatform { JS , JVM , NATIVE common } LinuxAndJS allExceptJvm allExceptJs JVM drawin Windows macos iOS linux js jvm

  37. What are we even supposed to do? subset-of { MACOS, IOS, LINUX, JS } common {LINUX, JS} LinuxAndJS allExceptJvm allExceptJs {JVM} JVM drawin {WIN} Windows macos iOS linux js jvm

  38. Experiments section: dependencies

  39. A peek into Gradle Module Metadata 1. build.gradle settings.gradle plugins { rootProject.name = '<project-name>' id ‘maven-publish’ } group = '<group.id>' version = '<my-version>' 2. $ ./gradlew publishToMavenLocal 3. $ cd ~/.m2/repository/<group>/<id>/<project-name>

  40. Example: Gradle Module Metadata in MPP ➜ mpp pwd /Users/dmitry.savvinov/.m2/repository/hello/mpp ➜ mpp tree -L 1 ├── my-mpp-lib │ ├── 1.0-SNAPSHOT │ │ ├── maven-metadata-local.xml Gradle module metadata │ │ ├── my-mpp-lib-1.0-SNAPSHOT.module │ │ └── my-mpp-lib-1.0-SNAPSHOT.pom │ └── maven-metadata-local.xml ├── my-mpp-lib-js ├── my-mpp-lib-jvm ├── my-mpp-lib-macosx64 └── my-mpp-lib-metadata

  41. Example: Gradle Module Metadata in MPP "variants": [ { "name": "js-api", "attributes": { "org.gradle.usage": "kotlin-api", "org.jetbrains.kotlin.js.compiler": "legacy", "org.jetbrains.kotlin.platform.type": "js" “Hey, I have a JS-part!” }, "available-at": { “Here’s where you should look for it” "url": "../../my-mpp-lib-js/1.0-SNAPSHOT/ my-mpp-lib-js-1.0-SNAPSHOT.module", "group": "hello.mpp", "module": "my-mpp-lib-js", "version": "1.0-SNAPSHOT" }

  42. Native dependencies

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend