Kotlin Compiler

0 views
Skip to first unread message

Canumil Flowers

unread,
Jun 30, 2024, 8:35:56 AM6/30/24
to chipzetscase

Unzip the standalone compiler into a directory and optionally add the bin directory to the system path. The bin directory contains the scripts needed to compile and run Kotlin on Windows, macOS, and Linux.

You can try packaging the Kotlin compiler as an Android app, and this could work, but there is no ready-made library that you can simply plug in into your app. Also note that the Kotlin compiler has fairly high CPU and memory requirements, which means that compiling even small files on old Android devices could take minutes.

@MohamedWS Did you manage to make it? I also have to compile runtime Kotlin code on Android, but kotlin-compiler dependency gives me several problems on compile time.
If you made it please show me how, thanks.

Incidentally I did just that recently on a project (I fixed up the maven plugin so it can support different source paths for different execution phases (JVM 'compile' versus 'js' etc) such as in this pom.xml. I did cheat in the standard library in kotlin and use a naming convention (excluding *JVM.kt files on the JS compile) which lets you keep code closer together; but I guess separate directory trees is maybe cleaner.

Yes, it is a good variant to set an option in build.gradle. It will be useful for a simple use-case when we want to set constants. In this case we can set several constants (but as variables) eighter with repeating a block, or destructing them:
1.

@wdoker , Your method works, but it is not good as the #if conditional compilation. Just think about what if that optional feature needs a bulk array? That bulk array can be wiped out if the #if feature is available. For that reason, Kotlin should add the #if conditional compiltion feature.

You can very easily turn that into a singular constant if-check in release builds and the fully-fledged normalised checking in debug builds.
Simply have a custom require function that knows about a const val DEBUG: Boolean like so:

Failed to download Kotlin Compiler Maven artifact (org.jetbrains.kotlin:kotlin-dist-for-jps-meta:1.8.20-release). The search was performed in the following repos: You can use Kotlin compiler which is bundled into your IDE. Select 'Bundled' version in 'File Settings Build, Execution, Deployment Compiler Kotlin Compiler Kotlin Compiler version'

I fixed it by following the instructions in the notification, except that "Kotlin Compiler" is in a top level settings menu in my version of Android Studio (2022.3.1 Patch 1), so I just went there and changed the "Kotlin compiler version" selection to be the bundled version.

Several existing answers effectively say to follow the instructions from the error message itself. That's a very reasonable strategy, but I found the most convenient solution was to delete the offending config file, which is .idea/kotlinc.xml.

I'm working at a large Java/Kotlin project at my company. It's several 100k lines of server-side code, with millions more coming in through dependencies. The Kotlin compiler sure has its work cut out for it. But as of late, the team noticed that the compiler was getting slower and slower, even though the project source size wasn't growing nearly at the same rate. Also, builds were consuming an abundance of CPU resources - on all available cores. Build times for a full project build had increased from about 2 minutes to more than 10 minutes. Something was definitely wrong.

Like many other folks out there, we use IntelliJ IDEA to write our source code, which is then handed to Gradle to build it. Nothing too complicated, right? Well, if we take a closer look, this is what actually happens...

The conclusion here is that no matter how much memory you assign to IntelliJ IDEA, it won't change the amount of RAM available to kotlinc upon build. Also, no matter how much memory you give to gradle, since kotlinc is its own process, it won't benefit from it.

We put this line into a file named gradle.properties, which is located right next to our gradlew executable (so, top-level in the project). This will assign 8GB of RAM to the gradle process, as well as another 6GB dedicated to the kotlin compiler.

You can of course play with the numbers. It's an implementation detail of the kotlin gradle plugin whether it calls kotlinc as a standalone process or embedded, so I took the defensive option and assigned more RAM to gradle than to kotlinc, but other configurations may work as well.

Now, if you change those properties in the file and save it, your kotlin compiler may still be slow and/or run out of memory. That's because your gradle daemon may still be running in the background, using your previous settings. Also, IntelliJ has an abundance of caches. The surefire way to make sure your changes are actually taking effect is to:

Our builds are now a lot faster again! We went from over 10 minutes at 100% CPU back to less than 1 minute, with much more reasonable CPU loads. Because the change was done in the build setup, our CI/CD server builds are now faster as well.

If your Kotlin compiles take way longer than they should, and your CPU goes crazy on all cores while kotlin is compiling, consider increasing the maximum heap size of your kotlin compiler. It may be running low on memory.

Glad to help out! It's ridiculous in many ways. It's so hidden and seemingly insignificant, yet has a huge impact. It's unaffected by any gradle setting. It's also unaffected by the Xmx setting of IntelliJ itself. It's not documented prominently anywhere.

Unfortunately I don't see a place where I can do the same for Kotlin. This makes it not possible for me to use Quasar-Kotlin. I want to switch to M14 even though I have 1.0 beta installed. How can I change back?

The compiler bundled to Kotlin plugin (IDE) must be greater or equal than external compiler (project) used for building modules. So update Intellij IDEA to be compatible with the most up-to-date plugins.

I recommend is to synchronize gradle with a non-existent version in order to clean the external libraries. This is because it could happen that our libraries continue to use the old version of the compiler after updating.

You can't do this at the moment. Building your project in IntelliJ IDEA always uses the version of the Kotlin compiler bundled with the plugin, regardless of what your build.gradle file says. If you need to downgrade to M14, you need to install the M14 version of the plugin.

This version (1.0.0-beta07) of the Compose Compiler requires Kotlin version 1.4.32 but you appear to be using Kotlin version 1.5.0 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!)

As of Compose 1.0.1, and Studio BumbleBee latest update (as of now), the required version of Kotlin required by compose is 1.5.10, however the Bumblebee update does not contain the kotlin version declaration even in the buildScript block. Now, you must change the declared dependency in the settings.gradle file, which is also where the studio picks it up from. Now, please note that even if you declared the correct version in the buildScript block in the project level build file, the project won't compile because studio will still fetch the version from the same place.

Also, if you are having a hard time finding out which version is required by the respective version of Compose, you can make the project, and when it fails, there's an option to run with scan to see full log output, which exposes the same. Alternatively, you could just edit it in the settings make it the default, whatever.

I had this problem when trying to migrate the old project to compose. For me, the solution was to create a compose activity. This can be done by hand or you can create an empty compose activity from the gallery.

e: This version (1.0.0) of the Compose Compiler requires Kotlinversion 1.5.10 but you appear to be using Kotlin version 1.5.20 whichis not known to be compatible. Please fix your configuration (orsuppressKotlinVersionCompatibilityCheck but don't say I didn't warnyou!).

We are excited to announce that with the upcoming release of Kotlin 2.0, the Jetpack Compose compiler will move to the Kotlin repository. This means that a matching Compose compiler will release alongside each release of Kotlin. You will no longer have to wait for a matching Compose compiler release before upgrading the Kotlin version in your Compose app. The Compose team at Google will continue to be responsible for developing the compiler and will work closely with JetBrains, our co-founders of the Kotlin Foundation. The version of the Compose compiler now always matches the Kotlin version. The compiler version is therefore jumping to 2.0.0.

You might currently directly referencing the Compose compiler in your build setup, rather than using AGP to apply the compose compiler plugin. If that is the case, note that the maven artifacts will also change:

I have a Java only multi module Maven project in IntelliJ IDEA and I can see IDEA calling a Kotlin compiler whenever I rebuild a module or choose to run all tests. This is shown in the background processes bar. It sometimes shows Kotlin: connecting to daemon as well which seems to take quite some time.Is there a way to tell IDEA to ignore Kotlin completely for a certain project? I guess the build times could speed up a little bit that way. I know I can disable the Kotlin plugin but that's not what I want as it would be disabled for all projects.

Write, Run & Share Kotlin code online using OneCompiler's Kotlin online compiler for free. It's one of the robust, feature-rich online compilers for Kotlin language. Getting started with the OneCompiler's Kotlin editor is easy and fast. The editor shows sample boilerplate code when you choose language as Kotlin and start coding.

The only way to get joint compilation across JVM languages would be if every language supported an explicit stubbing mechanism. This is not the case, so joint compilation of Groovy and Kotlin is not possible

And I do kind of agree with Stefan regarding limiting the number of languages in a single project. On some days writing Java I wish I could exclusively use two alternative languages and skip out on Java completely though

d3342ee215
Reply all
Reply to author
Forward
0 new messages