How do I configure projects to build common source code for multiple target platforms?

Answered

I have a legacy application written in Java which ran on a server with a web front end. That application was later migrated in part to GWT with the intent of running the application entirely within a browser and thereby remove the dependency on a servlet engine. Today, I want to convert that project into Kotlin with the goal of enabling it to compile and deploy to a JVM, a web browser when compiled into JavaScript, Android (perhaps even iOS someday), and to run natively on Windows, MacOS, and Unix/Unix-like systems.

Granted, each target requires target-specific code, especially for the user interface. However, a great deal of the code base implements algorithms and processes which do not need to change for each target platform so long as they are implemented in a language which can be compiled for deployment to the target platform. Hence, the interest in using Kotlin. (C would be another option if Emscripten were used to generate JavaScript for web browsers, but that is not the approach I would like to take today.)

With that background for context, I am having difficulty figuring out how to configure my projects in IntelliJ in order to build common source for two or three of my intended target platforms. Because project configuration includes the specification of SDK, run-time libraries, etc., I assume that means I should have a separate project for each target platform which requires a different configuration. The significant differences among JVM, JavaScript, and native mean I can not use libraries compiled in a shared module or a separate library project on which the target projects depend. Instead, each project needs to compile the shared source code within the target platform project.

So, with shared source code managed by a version control system (Git at the present time), how do I configure multiple projects to share common source code, including the ability to edit that source code and commit changes?

0
4 comments

Support for Kotlin projects targeting multiple platforms will be released in a future version of Kotlin. At this time there is no good solution for such an environment.

Also, Kotlin-related questions are best asked in the Kotlin forum: https://discuss.kotlinlang.org/

0
Avatar
Permanently deleted user

@Dmitry Jemerov Thank you for your response. However, I really don't think Kotlin is the issue.

 

As a language, Kotlin now supports compiling source code to several targets which do not share any kind of intermediate form -- e.g. Java bytecode. This would be true of other languages as well if they could be compiled to run in a JVM, natively, or in a web browser when compiled into JavaScript. The problem is with trying to set up IntelliJ -- or most other popular IDEs -- to enable working on a shared code base which compiles to such disparate targets with no ability to use  compiled libraries or other forms of intermediate shared objects or modules. As such, mutli-platform Kotlin development is really only a single concrete example of the kind of problem I am having with using IntelliJ to do multi-platform development. For what it's worth, I also had similar issues in trying to develop Java code which was intended to be both compiled to run in a JVM as well as compiled into JavaScript via GWT in order to run it in a web browser.

 

Back before IDEs became common, we would use command line tools -- including editors, compilers, debuggers, and version control systems -- with the Make command which originated on Unix or other similar build tools to do what I am trying to accomplish now -- yes, Ant, Maven, and Gradle have replaced Make for Java and other JVM-targeted development and IntelliJ can build using them, but I am not entirely clear how to configure my IntelliJ projects and modules in order to do what I am trying to do even while relying on one of those tools (or just Make) to build for the various target platforms. A build process for multiple target platforms could be arbitrarily complex (often unnecessarily so), but it was flexible. Modern IDEs make much of the software development process more enjoyable (and, sometimes, more "productive"), but they often begin by focusing on particular silos which become overly constraining even while bringing a degree of standardization to software development which is often lost on developers focused on writing code rather than on managing and deploying it.

 

In any case, the problem I am having is with understanding how I can make IntelliJ work as a full-cycle IDE rather than use it just as a Java-to-Kotlin converter as well as an overdeveloped text editor and debugger while source code control and the build process is managed entirely outside of it.

0
Avatar
Permanently deleted user

How to add ios platform module  for kotlin multiplatform project by using itellij IDE.Please help me to find the way.

0

Please sign in to leave a comment.