Skip to content
UnknownJoe796 edited this page Sep 6, 2022 · 3 revisions

This is all written for .gradle.kts.

Root Script

In your root buildscript, insert this to start using the plugin:

buildscript { 
    // ...
    val khrysalisVersion: String by extra
    classpath("com.lightningkite.khrysalis:plugin:$khrysalisVersion")
}

This will make the Khrysalis plugin available for usage elsewhere in your project.

Subproject Script

To make a given subproject translate, we'll do the following:

Add the Plugin

plugins {
    // ...
    id("com.lightningkite.khrysalis")
}

Add dependencies

val khrysalisVersion: String by extra
dependencies {
    // ...

    // These add the compiler plugins for Khrysalis - without these, the plugin's tasks will not work.
    kcp("com.lightningkite.khrysalis:kotlin-compiler-plugin-swift:$khrysalisVersion")
    kcp("com.lightningkite.khrysalis:kotlin-compiler-plugin-typescript:$khrysalisVersion")

    // This is a very-light runtime that essentially adds a few minor functions and annotations
    api("com.lightningkite.khrysalis:jvm-runtime:$khrysalisVersion")

    // This loads the base set of 'equivalents' - AKA, information about how to translate specific calls to libraries.
    equivalents("com.lightningkite.khrysalis:jvm-runtime:$khrysalisVersion:equivalents")

    // You can load your own equivalents as well.
    // If you depend on another local Khrysalis subproject, you can do this:
    api(project(":other"))
    equivalents(project(":other", "equivalents"))
}

Configure the Khrysalis destination

khrysalis {
    // If this module is a library, turn this on.  It will generate information to export so other projects can translate too.
    libraryMode = true

    // iOS configuration
    iosProjectName = "IosProjectName"  // The name of the iOS module
    iosProjectFolder = rootDir.resolve("IosProjectName")  // The project's base folder.
    iosSourceFolder = rootDir.resolve("IosProjectName/Classes")  // The location to place the translated files.

    // Web configuration
    webProjectName = "web-project-name"  // The name of the NPM module
    webProjectFolder = rootDir.resolve("web")  // The NPM project's base folder.
    webSourceFolder = rootDir.resolve("web/src")  // The location to place the translated files.
}

Running the translation

You can run the translation using the Gradle tasks in the ios and web groups.

Note that your project must compile in Kotlin successfully already to use them.

Commonly Paired Libraries

  • RxPlus libraries - a set of libraries built to make Android development more efficient and already have prepared Khrysalis equivalents.
  • Android Layout Translator - a Gradle plugin that translates your layouts and resources to web and iOS.
  • Lightning Server - A server backend library which generates a Khrysalis-compatible SDKs for the APIs that you write.

Troubleshooting

Missing Translations

This issue is characterized by seeing the Kotlin name of something used in the TypeScript or Swift outputs. It means the equivalent information is not being loaded correctly or is missing. It is most likely you missed an equivalents() dependency.

If certain translations don't seem to be working, you can use the Gradle task listEquivalentFiles to list every equivalent file it is successfully loading. That should help identify such issues.