-
Notifications
You must be signed in to change notification settings - Fork 25
Kotlin Language
With Rush v1.2.0, extension developers get first-class Kotlin language support in Rush! You can:
- Write your extensions in pure, idiomatic Kotlin
- Use libraries written in Kotlin in new or existing extensions
- Interop Kotlin in your existing extensions
-
Fire up your terminal and
cd
into the directory you wish to create an extension. -
Run
rush create <ext_name>
. -
Enter the extension info in shown prompts and then select Kotlin as the extension's language.
-
Hit enter and voila! Your extension is created.
-
In your extension's metadata file (
rush.yml
), add the following:build: kotlin: enable: true
-
Then, open the
proguard-rules.pro
file and replace the whole file with this:-keep public class <your_ext_package>.* { public *; } -keeppackagenames gnu.kawa**, gnu.expr** -optimizationpasses 4 -allowaccessmodification -mergeinterfacesaggressively -repackageclasses '<your_ext_name>/repack' -flattenpackagehierarchy -dontpreverify
Note: Make sure to replace
<your_ext_package>
(on the 1st line from the top) with your extension's actual package name.
Note: Make sure to replace<your_ext_name>
(on the 3rd line from the bottom) with your extension's actual name. -
Done! You're now ready to use libraries written in Kotlin and/or mixing Kotlin code with the existing Java code.
3.1. Build the extension like how you'd normally using the
rush build
command and when you're ready to ship the extension userush build -r
to reduce the size of your extension.
-
Why is the extension size so big when built without
-r
flag?
Ans: This is because AI2 doesn't have native support for Kotlin yet. And because of this, Rush needs to include the Kotlin Standard library with every extension that uses Kotlin (or libraries written in Kotlin). Although, is a solution for this problem. Passing the release flag (-r
) or the optimize flag (-o
) while building will shrink your extension's size by almost 99% by removing all the unnecessary stuff from the Kotlin Standard library. -
Why does the compilation takes so long?
Ans: That's just how Kotlin compiler works, unfortunately. In most cases, it's way too slower than Java compiler (with some exceptions). There's not much that can be done which will improve the performance significantly, but if you think improvements can be done, I', always open to suggestion and PRs! 😃 Tip: You can reduce the build time by some margin by optimizing the extension (with-o
) on every build. Unlike the release flag (-r
), this doesn't invalidates the build caches, but optimized the Kotlin Standard library reducing the overall time required by steps such dexing. -
Can I use all the APIs of Kotlin Std. library in extension?
Ans: Yes, you can!