https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

Dron Bhattacharya

02/13/2023, 6:07 PM
I want to create a CLI/terminal-based application like vim for editing files. It does not need to be as complex as vim. I can be like nano too. But i don't how to start. In python and Javascript there are many libraries to create UI for terminal interface. But how to build this in kotlin. i have figured that I have to use ncurses.
l

Landry Norris

02/13/2023, 6:10 PM
There’s definitely options. If you like compose, you can take a look at mosaic,, you can look at clikt, you can use cinterop with ncurses. For commands with flags, you can use kotlinx-cli
d

Dron Bhattacharya

02/13/2023, 6:19 PM
is it possible to use kotlin without intellij? Like in c++, we can create a cpp file and then from terminal use compiler like clang.
l

Landry Norris

02/13/2023, 6:19 PM
You can use gradlew tasks, or you can use the kotlinc cli compiler.
d

Dron Bhattacharya

02/13/2023, 6:20 PM
can u point me to some resources for reference
l

Landry Norris

02/13/2023, 6:20 PM
kotlinc doesn’t have much documentation, so if the project is more than one file, I’d use gradle still, but I’ve used kotlinc before.
e

ephemient

02/13/2023, 6:20 PM
just check out any Kotlin project, it almost certainly uses Gradle
a

Adam S

02/13/2023, 6:21 PM
the Kotlin command line compiler has docs here: https://kotlinlang.org/docs/command-line.html
l

Landry Norris

02/13/2023, 6:21 PM
Here's a reference for the cli compiler. Some notes: There’s different commands for the different compilers (kotlinc for JVM, kotlinc-native for Native, and I believe kotlinc-js for JS). You have to pass in all Kotlin files at once. In C++, you compile one file at a time, then link at the end. You pass all at once in Kotlin
d

Dron Bhattacharya

02/13/2023, 6:22 PM
what should I use maven or gradle? I am new to these.
G 1
e

ephemient

02/13/2023, 6:23 PM
the Kotlin Gradle Plugin is supported as the primary way to use Kotlin. the Maven plugin… less so
1
l

Landry Norris

02/13/2023, 6:23 PM
Depends on what you’re most familiar with. I use gradle typically, but maven should work fine.
I would use IntelliJ to create the project personally. After that, you can just use gradle to build/run. You can run
gradle tasks
and it wll print out a list of tasks the project can run.
a

Adam S

02/13/2023, 6:26 PM
there’s a guide on how to set up a Kotlin project here: https://kotlinlang.org/docs/jvm-get-started.html the Kotlin Koans are also a good intro https://play.kotlinlang.org/koans/overview
👍 1
d

Dron Bhattacharya

02/13/2023, 6:31 PM
If I want to start a kotlin project, can i do it without using itellij??? How can I? I like the IDE. But I like to do things first by my own hands to get familiar with the process and also know how everything works under the hood.
l

Landry Norris

02/13/2023, 6:32 PM
Will this project be Koltin/Native or Kotlin/JVM?
d

Dron Bhattacharya

02/13/2023, 6:33 PM
Kotlin/JVM simple cli application...
l

Landry Norris

02/13/2023, 6:34 PM
create a folder for the project, then create build.gradle.kts (file) and src (folder). Add
Copy code
plugins {
    kotlin("jvm") version "1.8.10"
    application
}
to the build.gradle.kts and create main.kt in src. Copy
Copy code
fun main() {
    println("What's your name?")
    val name = readln()
    println("Hello, $name!")
}
into main.kt and you should have the most basic project.
If you have gradle installed, run
gradle tasks
and see what the output says. If you don’t then copy the gradle folder and gradlew (gradlew.bat for Windows) from another project.
d

Dron Bhattacharya

02/13/2023, 6:36 PM
after this, how can I run and compile the code to create a exe?
l

Landry Norris

02/13/2023, 6:37 PM
When you run gradle tasks (or gradlew tasks if using the wrapper), it will list the tasks you can use. There should be a few tasks related to building. If everything was set up right,
gradle build
(or gradlew if using the wrapper) should work.
a

Adam S

02/13/2023, 6:39 PM
if you install Gradle, then run
gradle init
in an empty dir it will guide you through setting up a basic project - you can select ‘Kotlin application’
💯 1
👍 1
but…. just use IntelliJ. It doesn’t set up that many files, and the guide answers the questions you’re asking. Then you can ask about anything that’s not covered.
d

Dron Bhattacharya

02/13/2023, 6:42 PM
IntelliJ is very useful. But I just want to be able to do stuff without the IDE. I like to use my hands for the first few times to just practise and know the process.
l

Landry Norris

02/13/2023, 6:43 PM
In that case, either gradle init or following the steps I mentioned will help with understanding better.
👀 1
Once the project is set up, I’d use IJ, though, since it gives syntax highlighting, refactoring tools, and suggestions.
e

ephemient

02/13/2023, 6:44 PM
I write all my projects by hand, but Gradle is complex enough that I think you'll have an easier time starting off in the IDE first. https://docs.gradle.org/current/userguide/userguide.html is fairly comprehensive (for everything built-in to Gradle, not Kotlin) but it is a lot to ingest
a

Adam S

02/13/2023, 6:44 PM
k

Kirill Grouchnikov

02/13/2023, 6:48 PM
You don’t need to send individual questions to the entire channel. You’re already getting answers here.
👍 1
Not sure which parts are you referring to as “and also know how everything works under the hood”. Building things from command line vs building things in the IDE is kinda the same. You either copy-paste the right incantation for the compiler and all its flags in the terminal every single time, or you click the build button in the IDE. Unless maybe you type the build command manually every single time? As for under the hood, unless you’re going under the actual hood to see what the Kotlin compiler does to generate bytecode, and how the JVM interprets that bytecode to run on the specific hardware, is it really under the hood?
d

Dron Bhattacharya

02/13/2023, 6:55 PM
I just want to know what happens when I click the run button or the build button. Like most people i also started learning kotlin from the IDE.
l

Landry Norris

02/13/2023, 6:55 PM
I’d say there is value in at least understanding the command line compiler. I worked on a side project in the early days of Kotlin/Native where I had to pass flags down to the clang build step, or where I had to use a custom LLVM build step, so I needed the Kotlin compiler to produce LLVM bitcode. I was very glad to have had practice with the command line compiler before that.
Most IDE features map pretty close to a gradle task. When you click ‘clean project’, it runs gradle clean, when you click ‘build project’, it runs gradle build. When you click run, it may start a gradle run task or a build, then run the built executable. Sometimes, it will pass in a flag or two (like for debug runs).
🙌 1
d

Dron Bhattacharya

02/13/2023, 7:29 PM
thanks for helping, all of you. I have set up an initial project from CLI. And now I am in 1 of my favorite place "NVIM". I know it is not suitable for large-scale Kotlin projects.... but I am just learning and exploring now...
👍 2
84 Views