Any plans for having conditional compiling?


Hi people!

I wonder if there are any plans for introducing features for conditional compiling so we can support both Java and Javascript targets in the same project?

Maybe something like a convention based on file extensions? For example,

  • Canvas.js.kt

and then the compiler choses file accordingly to what the current backend is.

How does this sound? If not, what is/will the standard practice be for this problem?

Regards, Tommy


Why not factor platform-specific parts into separate modules?


Oddly enough I didn't think of that. :8}


Incidentally I did just that recently on a project (I fixed up the maven plugin so it can support different source paths for different execution phases (JVM 'compile' versus 'js' etc) such as in this pom.xml. I did cheat in the standard library in kotlin and use a naming convention (excluding *JVM.kt files on the JS compile) which lets you keep code closer together; but I guess separate directory trees is maybe cleaner.

It might be nice for IDEA to have a view where the ‘common’, ‘jvm’ and ‘js’ kotlin code could be viewed in a single source tree to avoid having to do too much tree expanding/collapsing.


Hi, I’d like kotlin to have some conditional compile control syntax
like #if
from my android developer experience:
I hope i can write such code:

class MyActivity:Activity(){}

that means I want a open class in Debug Mode. while a final class in release mode.


is it a library? Why would you need it to be a final class in release mode? Which advantages does it bring?