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
2
votes
1 answer

Is there a way of limiting stdlib functions' visibility in Kotlin?

Kotlin comes with many standard library functions, a lot of which are visible by default without actually importing them. So functions like listOf, arrayListOf, ArrayList(), ... are de facto inserted into global namespace. Is there a compiler…
Andrej
  • 280
  • 4
  • 12
1
vote
0 answers

Is there a way to tell kotlin compiler (via gradle) to fail when some package isn't matching file location?

I've seen multiple cases in which my lazy coworkers copy paste a file without changing the package. Kotlin is cool about it, and the only one issuing a warning is the IDE. Is there a way so that the compiler fails on THAT warning? or maybe... via…
caeus
  • 3,084
  • 1
  • 22
  • 36
1
vote
0 answers

Kotlin K1 to K2 plugin migration. analysisCompleted, binding context slicing

I need a suggestion on K1->K2 Kotlin compiler plugin migration. I have a K1-compatible plugin that overrides AnalysisHandlerExtension::analysisCompleted and uses a bindingContext to get a slice of TYPEs used in…
Sergei Rybalkin
  • 3,337
  • 1
  • 14
  • 27
1
vote
1 answer

Kotlin Error 'unresolved reference' appears when trying to run Java Code from a Kotlin file

Referencing Problem when Java Class is used in Kotlin. There is the Java class Base32Decoder.java and code from this class is used in the Kotlin file hello.kt. When I try to run Java code through a Kotlin file, an error occurs because of no…
EpicAdidash
  • 137
  • 8
1
vote
1 answer

kotlinc: unresolved reference

I have two files: Main.kt: package A fun gg1() = "hello" Main2.kt: package B import A.gg1 fun gg2() = gg1() Trying to compile the code: iv@LAPTOP:~$ tree . . ├── A │   └── Main.kt └── B └── Main2.kt 2 directories, 2 files iv@LAPTOP:~$…
VanechikSpace
  • 265
  • 2
  • 9
1
vote
0 answers

How can kotlinc without gradle or IntelliJ IDEA take less than 10 seconds to compile Hello, World?

kotlinc -include-runtime -d hello.jar hello.kt or simply kotlic hello.kt takes over 10 seconds with the below hello word program. fun main() { println("Hello, world") } I have used oracle's and openjdk's java 17. I am using kotlin 1.80. I have…
mmm111mmm
  • 3,607
  • 4
  • 27
  • 44
1
vote
0 answers

Compile .kt files nested in folders with kotlinc

I want to use kotlinc to compile multiple files that are organized in folders, like in this minimal example: Main.kt only calls helper.kt which contains When I call: kotlinc *.kt -include-runtime -d Main.jar I get the error I guess the problem is…
Moritz Groß
  • 1,352
  • 12
  • 30
1
vote
0 answers

How to find default kotlin compiler argument values?

Currently I use a bunch of compiler flags in my gradle build file. I'm sure some of these are defaults that I would prefer not to specify explicitly (and thereby have them updated automatically as the compiler is updated). But I cannot find any…
user2297550
  • 3,142
  • 3
  • 28
  • 39
1
vote
1 answer

Error on batch compiling Kotlin source code in Windows

In Microsoft Windows 7 I have two Kotlin source codes in C:\new directory: hello1.kt hello2.kt I can compile them separately in command line which its current working directory is C:\, for example >kotlinc hello1.kt. But when I try to do batch…
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
1
vote
1 answer

How to compile kotlin script to a jar

I have a kotlin script file named CheckUtils.kts. I want to compile the CheckUtils.kts to a jar which can be run with "java -jar CheckUtils.jar". I try to use kotlinc to compile kts file to a jar, but i failed. kotlinc src/CheckUtils.kts…
1
vote
1 answer

What is the scope of variable defined in kotlin console?

For example, I enter the kotlin console via kotlinc command. Then define a variable: val pi = 3.14, what is its scope ? I have tried const val PI = 3.14, which would be an error as following: error: const 'val' are only allowed on top level or in…
Eric
  • 22,183
  • 20
  • 145
  • 196
1
vote
1 answer

kotlinc -script with multiple files

I have a Kotlin script which I'm using for testing. In order to run it quickly, I'm using kotlinc -script to evaluate it which prints me the result straight away in the console. Now, when the script becomes big enough, I want to split it into…
Dinu
  • 390
  • 1
  • 2
  • 12
1
vote
1 answer

How do I add dependencies to my custom Gradle plugin?

I get a NoClassDefFoundError when trying to add a dependency to my custom Gradle plugin, and I haven't found a way to solve it. Added to the plugin's dependency…
neu242
  • 15,796
  • 20
  • 79
  • 114
1
vote
1 answer

Kotlin standalone compiler manual installation

Looking at https://github.com/JetBrains/kotlin/releases/tag/v1.3.0, there is a generic multi-platform zip file (kotlin-compiler-1.3.0.zip) and some platform-specific ones (e.g. kotlin-compiler-1.3.0-release-windows-x64.zip). Looking inside the zip…
DodgyCodeException
  • 5,963
  • 3
  • 21
  • 42
1
vote
0 answers

kotlinc equivalent for --patch-module from javac

Does kotlinc have an equivalent option for javac's --patch-module? e.g., -Xmodule-path= is the kotlinc equivalent option for --module-path from javac, but I haven't yet found an equivalent for --patch-module.
XDR
  • 4,070
  • 3
  • 30
  • 54