I want to create a tutorial repo using Kotlin Native and Go for students.
The repo should be organized in multiple separate tiny modules.
Each module has just 2 files: implementation file + test file.
Any 2 modules should not see each other code and without conflict if they declare the same type again and again in multiple modules.
It’s easy to create a Go module like below without any extra setup. Autocompletion works in IntelliJ IDEA and it can run the test file.
Students only need to install Go (ex. scoop install go), then tell the IDE where to find the Go installation and ready.
How could I do the same for Kotlin Native files in IntelliJ IDEA without extra build tools like Gradle/Maven?
Students should only need to install Kotlin Native compiler (ex. scoop install kotlin-native), then tell the IDE where to find the Kotlin Native compiler and ready the development with Autocompletion and running the test or main file.
I feel very stupid to ask students fighting with a lot of setups before seeing their code running.
They should be interested in learning Kotlin Native immediately in the first minutes opening their IDE. Their code should be compiled fast and run immediately without seeing complex things if using Gradle/Maven.
Another problem is that if I try to mark 2 separated directories as sources root to enable Autocompletion, IntelliJ will make conflict error like below, that prevents teaching separate modules.
Extra question: Go supports goroutine directly without dependencies. How to also add kotlin coroutine in the easiest way?
PS: I choose Go and Kotlin Native, because I am targeting native distributed systems. Go is for most current projects and Kotlin Native will be the 2nd option for the future projects when it reaches production ready status.
It feels like trying to force a tool X to be a tool Y.
You can follow the instructions here and use the compiler directly, as we do with gcc and others. Although, I’m not sure if IntelliJ will offer a straightforward way to compile this to native. And things may be not very smooth if trying to do anything more than the basic hello world.
Then use… Gradle. This is actually one of the main reasons why it has been invented in the first place and why people use it. We don’t have to go through 5 pages of README and local setup just to build and run the project. Most Gradle projects run just fine on entirely clean OS (and entirely dirty as well), with only Java installed - by entering simple
./gradlew run (or opening in IDE). It automatically downloads the Gradle itself, downloads required Java or Kotlin compilers, any additional libraries, etc. Build process is quite independent of the local setup and environment.
Of course, it adds complexity, but if you setup the project for your students, then they don’t really have to look there - similarly, as they don’t read the source code of the compiler they use.
Use separate packages, entirely separate projects or separate Gradle modules. Again, we can easily create a gradle config which will allow to have a single project with multiple separate source sets and IntelliJ will load it up automatically.
The easiest? Use Gradle You add a single line in the Gradle config and your students don’t have to think or even know about it. Alternatively, they have to download the coroutines library for their specific platform and then probably use some extra args to
@broot thanks for your reply.
I showed an example of Go, which is like 1-2-3 effortless steps and take all advantages of the IDE right away. Students will not ask anything with this kind of setup in Go and concentrate on coding. Both teachers and students are happy.
Here, Kotlin Native forces to use Gradle with a complex setup for both teachers and students.
Even if teachers do everything, the performance of Gradle, especially when having a lot of sub-projects, is super slow.
Using compiler command directly is extremely fast, but unfortunately IDE doesn’t support that way. It only supports the slow Gradle for Kotlin Native.
Actually, I already have a setup using Gradle, but I still really want to find an alternative light way because of 2 reasons:
- Performance of Gradle is too slow, comparing to running Go module or kotlinc-native command
- Running Kotlin Native code shows a lot of distracted information if using Gradle
Honestly, Go is more friendly to students. Students concentrate more while working with Go, which shows very minimal and straight forward information when running the code.
With Gradle, teachers need to tell curious students that they shouldn’t care about this and that yet. I really hate to tell students to stop being curious like this. I love to encourage them to be curious and ask anything right away. While learning Go, the exposed information is minimal, so I am sure that they will not ask too tough questions and I can explain to them right away easily.
I am thinking about a workaround: downloading all required deps to the repo and using Ant to run kotlinc-native command directly. I’m not sure if autocompletion will work this way. Another disadvantage is that I need to keep the lesson to use only a small number of deps to avoid putting too much to the repo. I guess Ant is simpler and much faster than Gradle/Maven.
you could teach them how to use the command line compiler Kotlin command-line compiler | Kotlin Documentation
But how to enable IDE Autocompletion?
I Don’t know if it works the same for non-ultimate intellij versions but here i created a folder, inside them another couple of folders and put two distinct kotlin sources inside each one.
once i opened the parent folder with intellij, it detected one folder as kotlin sources with completion enabled.
the second folder i managed to add as source folder by configuring project structure:
please check if it works for you: GitHub - sombriks/simple-kotlin: https://discuss.kotlinlang.org/t/kotlin-native-and-intellij-idea-without-extra-build-tools-like-gradle-maven/27453/4
Hey, thanks for trying.
In the OP, I already mentioned the conflict problem of manually marking 2 folders as sources root.
Anyway, I will try using Ant to use kotlinc-native command and libs directly to see if I can make a similar simple/friendly experience for newbies like go.mod setup.
For installing Go/KotlinNative, it’s easy with brew on non-windows and scoop/chocolatey on windows
Regarding the name conflict. Again, couldn’t you use separate packages? You plan to put each module in a separate directory anyway, so you can have a single source root and inside it multiple directories, which are at the same time Kotlin packages. Additional advantage is that students won’t have to setup X source roots in IDE, but only one.
Ohh i missed that part!
Indeed with go it’s way more simple, but let me try once more, i think that nested modules for each kotlin project and proper output directory setup might do the trick.
I’ve updated the previous sample project with the related internal intellij configuration files.
Create java submodules managed by intellij and add kotlin support after that.
Besides that, it’s quite surprising that kotlin, a jetbrains product, struggles so hard to go simple!
I suggest using Kotlin notebooks or KScript. Notebooks have basic completion in Jupyter and full completion in IDEA Ultimate/Education. You need JVM of course. I do not understand, why do you want native execution.