<kotlinc> for updated sources only


#1

is there a way to tell <kotlinc> task to compile new/updated sources only as it's done in <javac>


#2

No, this is not possible in the kotlinc Ant task in the way it's supported in the javac Ant task. In fact I wouldn't recommend you to use that feature even on pure Java sources, because its implementation in Ant is very primitive (it only recompiles .class files which are older than the corresponding .java files, but never anything else like the dependent classes) and that often results in weird compilation errors. This is why very often you can see Ant build scripts intentionally wipe the destination directory before launching the compiler.


#3

Yes, it's a known issue of <javac>, but very often we can live with it. The actual thing is compilation time: for javac it's almost linear from amount of .java sources. When a project is small, compilation time of whole source tree doesn't matter lots. But I try to migrate a small enterprise project to Kotlin and the compilation becomes very time consuming. It kills almost all productivity I get from the language itself.


#4

Compiler performance is one of our primary goals at the moment, so hopefully it'll get better soon. Also if you're using IntelliJ IDEA, we have incremental compilation support there. No plans for true incremental compilation support in Ant yet, primarily because it's not done properly for Java, although it seems possible.


#5

I'm puzzled: what does ant have to do with kotlinc?

It seems to me the only difficulty to have smart recompilation in kotlinc is understanding which files depend on which other files (mostly by analyzing imports but I understand it’s a bit more subtle than that since there are other factors such as inlining and subclassing).


#6

How can I enable incremental compilation in IDEA? When I press Ctrl+Shift+F9 on a .kt source, kotlinc recompiles all sources in the src directory regardles source files modification (plugin version 0.12.1218.idea.142.3)


#7

At the moment Kotlin's incremental compilation code in IntelliJ IDEA reuses most of the logic of the IntelliJ's internal build runner, JPS, which performs bytecode-level analysis to find out what files need to be recompiled and maintains some caches to do that quickly. I suppose it's not very easy to extract that to a standalone library and to configure it properly to be run efficiently from a command-line build system such as Ant.


#8

This may happen if for some reason the compiler thinks other files depend on this file. For example, if it has an inline function which is used in many other files, you may end up recompiling the whole module. Is there anything particularly interesting about this file?

Also please check if the incremental compilation is enabled in Settings -> Build, Execution, Deployment -> Compiler -> Kotlin Compiler -> Enable incremental compilation.

Finally you can try using the latest snapshot builds (0.13.*), where the incremental compilation support had been improved significantly. If that doesn’t help, please report an issue at youtrack.jetbrains.com. Thank you!