Gana
Gana

Reputation: 131

Does the Kotlin compiler compile java files?

I have a project with both .java and .kt files. Does the Kotlin compiler compiles both .java and .kt files or does it only compile my .kt files?

Upvotes: 8

Views: 7119

Answers (2)

Mike Strobel
Mike Strobel

Reputation: 25623

No, kotlinc compiles only Kotlin files (.kt). A mixed-language project requires combining both kotlinc and javac. If the references flow only one way, e.g., if Java code references Kotlin code and not the other way around, then the compilation order is pretty easy to figure out. In that situation, you would compile the Kotlin code first, then include the output in the classpath to javac when compiling the Java code.

If the two are more intertwined, it becomes a little more complicated. Looking at this thread, it appears you'll need to run kotlinc first, passing in any referenced Java source files (as the .class files won't be available yet). The class files built by kotlinc can then be included in the classpath when you compile your Java files.

Upvotes: 15

Jason Sperske
Jason Sperske

Reputation: 30416

By itself it does not, however one of the requirements to run the Kotlin compiler (according to its documentation https://github.com/JetBrains/kotlin) is the JDK, so if you have Kotlin you also have javac

Upvotes: 1

Related Questions