Writing client and server code inside a IntelliJ project


is it possble to create a kotlin project where i can write server-side code as well as client-side code (kotlinJs) and use a kind of shared library for both? i already created a tomcat server running with kotlin, and created a kotlinJs client modul and can run this project without problems, but i have the problem that i can not reuse the dto objects for both and have to copy the dto class for the server and for the client, what is not a elegant solution and creates duplicate code.

what i need, is to be able to send a ajax request to the server, which creates a dto, transforms it to json and sends it back to the client. in the client i want to tansform this json back to the same dto (and not a copied one). as mentioned, this works perfectly with the copied dto class, but should work with only cone class definition.

is this possible with kotlin and intelliJ?
and if yes, how can i do it?


Multiplatform projects will be supported in 1.1. In Kotlin 1.0, the best you can do is symlink a source directory to the JS and JVM modules.


i never used symlink before so i might do something wrong, but i created a server modul with the dto package and a client module, and in the project-structure i made a symlink for the client module to the server directory containing the dto files. but this does not work as the server modul can not find my dto class anymore after the symlink.

anyway, i guess the most easy way is to copy all my dtos after each change and wait for kotlin 1.1 in the hope that this problem will be solved


At least when using gradle (the android variant as there is an android submodule) symlinks to source dirs don’t work as intellij will actually resolve the symlink and see that the sources are the same (with all the mayhem involved). The only workable way I’ve found is to have gradle copy the (jvm) source to another (js) module in a directory marked as generated source through the idea plugin for gradle. It works, but is brittle as it is easy to change the copy instead of the original.