Questions tagged [kotlinc]

Kotlin Compiler - Comes bundled with standard Kotlin package

Compile the application using the Kotlin compiler.

$ kotlinc hello.kt -include-runtime -d hello.jar

The -d option indicates what we want the output of the compiler to be called and may be either a directory name for class files or a .jar file name. The -include-runtime option makes the resulting .jar file self-contained and runnable by including the Kotlin runtime library in it. If you want to see all available options run

$ kotlinc -help

Run the application.

$ java -jar hello.jar

61 questions
49
votes
5 answers

@JvmDefault and how add compiler option

I need to make a default void method in a Kotlin interface. I ran into a problem and a hint said Usage of @JvmDefault is only allowed with -Xjvm-default option. Where do I need to write this Xjvm-default?
Evgesha
  • 491
  • 1
  • 4
  • 4
13
votes
2 answers

How do I exit out of the Kotlinc command-line compiler

So, how do I exit out of the Kotlinc command-line compiler? I entered kotlinc on my terminal and played with some kotlin on my Mac and now couldn't figure how to exit. It is like the first time I tried vim. Tried ctrl+c, exit, exit(), quit , quit()…
Harish
  • 1,433
  • 9
  • 21
10
votes
2 answers

How do I run tests compiling a kotlin file in memory and check the result?

So far I have import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler MyProjectCompiler.initialize("SampleKtFileOutput") .packageName("com.test.sample") .compile(File(someFile.path)) .result { ktSource: String -> K2JVMCompiler() …
Preston Garno
  • 1,175
  • 10
  • 33
9
votes
2 answers

Kotlin extremely slow compile time

Why is compiling and running Kotlin extremely slow (at least on my machine)? I have the latest version of Kotlin compiler installed on my machine. Specifically the command: kotlinc main.kt -include-runtime -d main.jar && java -jar main.jar It's so…
Kingvert
  • 101
  • 1
  • 6
7
votes
1 answer

How to use kapt from command line (with kotlinc)?

Official documentation instructs how to use kapt from Gradle and Maven. But how can I use kapt from command line, with kotlinc?
cubuspl42
  • 7,833
  • 4
  • 41
  • 65
6
votes
2 answers

Strange behaviour of Kotlin compiler or Java decompiler

This question is driven by my curiosity alone, so I would like to receive a full answer, rather than simple "yes" or "no". Let's consider this piece of code: // Is stored in util files and used to omit annoying (this as? Smth)?.doSmth() inline fun…
GV_FiQst
  • 1,487
  • 14
  • 30
6
votes
1 answer

Kotlin Script (.kts) - How to divide it into multiple files?

I have a Generator.kts file. When I execute it using: kotlinc -script Generator.kts everything works as expected. However, now my script has grown and I need to separate that class into multiple files. I did that but when I try to execute it again…
5
votes
1 answer

Will immutable objects with const parameters be optimized to be instantiated only once by the Kotlin compiler

There are many immutable classes in Java like String and primitive wrapper classes, and Kotlin introduced many others like Range subclasses and immutable Collection subclasses. For iterating Ranges, from Control Flow: if, when, for, while - Kotlin…
Shreck Ye
  • 1,591
  • 2
  • 16
  • 32
4
votes
0 answers

Can I build an android apk without "gradle" on command line?

Is it possible to create an apk without gradle via command line? My application consists of both kotlin and C++ code. Currently I used separate compilers for both kotlin and c++ code and compile them. Now I also got a requirement of many resource…
Rohan Pande
  • 301
  • 1
  • 5
4
votes
0 answers

Which Kotlin metadata version is used in Android Kotlin Compiler

Problem Android tools uses a custom version of Kotlin Compiler. Is there a way to understand which version of Kotlin metadata this custom compiler uses? Context Lints from Android-tools has a /android/tools/external/com-intellij/kotlin-compiler/…
Sergei Rybalkin
  • 3,337
  • 1
  • 14
  • 27
4
votes
0 answers

How to use a maven dependency in Kotlin REPL?

A Kotlin script with *.main.kts format can easily pull the dependency through the @file:Repository and @file:DependsOn annotations. But I tried something similar with the REPL: kotlinc-jvm -cp /lib/kotlin-main-kts.jar (specified…
4
votes
2 answers

Does the kotlin REPL have code completion?

I just opened kotlinc (which apparently defaults to kotlin-jvm ?) and dropped in some hello-world type code: data class Person(val name: String, val age: Int) { val isAdult get() = age >= 20 } Let's create an instance : val p = Person("ab",…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
4
votes
1 answer

How to run remote debug on local kotlinc

I want to compile some sample kotlin project using local compiler. I clone jetbrains/kotlin project from githib and build it. And now i have local compiler in /dist folder. How i need to configure gradle in sample project to use this local compiler…
spartaneg
  • 329
  • 2
  • 12
4
votes
1 answer

Including the reflection library in a jar output by kotlinc

I'm trying to get the reflection lib included in sample jar, but can't get it to work: $ kotlinc hello.kt -d hello.jar $ java -jar hello.jar Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics The runtime lib…
Basel Shishani
  • 7,735
  • 6
  • 50
  • 67
3
votes
1 answer

What are the performance differences between all the ways to declare a constant in Kotlin?

Since Kotlin doesn't allow you to directly declare constants inside a class like static members in Java, we have a couple of options on how to do it in Kotlin. My question is, what are the performance costs of each option, and which one is cheaper?…
jpegoraro
  • 315
  • 2
  • 10
1
2 3 4 5