Interplatform build


#1

There are plenty cases when one platform build is to be used in another platform.
For example:

  1. Use js compiled application in jvm one with webjars
  2. Integraion testing in js with the usage of a service built for jvm
    etc.

But for me it is not clear how to make interplatform building. If I just use in JVM

dependencies {
    implementation(project(":js-subproject"))
}

I receive an error:

          - Variant 'apiElements':
              - Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
              - Found org.jetbrains.kotlin.localToProject 'public' but wasn't required.
              - Required org.jetbrains.kotlin.platform.type 'jvm' and found incompatible value 'js'.
          - Variant 'compile':
              - Required org.gradle.usage 'java-runtime' but no value provided.
              - Found org.jetbrains.kotlin.localToProject 'local to :js-subproject' but wasn't required.
              - Required org.jetbrains.kotlin.platform.type 'jvm' and found incompatible value 'js'.
          - Variant 'compileOnly':
              - Required org.gradle.usage 'java-runtime' but no value provided.
              - Found org.jetbrains.kotlin.localToProject 'local to :js-subproject' but wasn't required.
              - Required org.jetbrains.kotlin.platform.type 'jvm' and found incompatible value 'js'.
....

in spite of js-subproject-0.0.1-SNAPSHOT.jar is properly compiled.

What am I doing wrong?


#2

What you are trying to accomplish is called Composite Build.
What you refer as “build” is actually a project.


#3

Thank you for your suggestion. May be I do not understand correctly, but composite build doesn’t look perfect for designated task.
Actually, both js and jvm projects are subprojects of one project. They reasonably share the same settings.gradle.kts file, dependencies versions, variables (project name, project version), etc. And I would not like to refuse all these benefits.
On the other hand, sometimes I want two different platforms to interact within the same multiplafrom project. For example, to use in the same integration test js client and jvm server. It is not clear for me how I can split one project into multiple included projects.


#4

Uhm, could you explain a little more precisely your usecase?


#5

Hello. This explanation might help: https://youtrack.jetbrains.com/issue/KT-26834#focus=streamItem-27-3150568.0-0


#6

Here https://github.com/svok/kotlin-multiplatform-sample you can see my sample project for integration between ktor as a backend in angular as a frontend. The integration goes well in general but with some difficulties. One of the is explained here and another is in topic Dependencies in kotlin-multiplatform-js and npm.

In the branch back-import-webjar I want to add proj-angularfront subproject to resources/webjars of the backend. If I do like here https://github.com/svok/kotlin-multiplatform-sample/blob/20513d8d2b3e3126457e221b58406dbea3ecc937/proj-backend/build.gradle.kts#L37 I get the mentioned above error. But I want to avoid splitting the subprojects proj-angularfront and proj-backend into separate projects like is supposed to be with composite build.

On the other hand I’d like to have a possibility to make automatic integration tests with started proj-backend as backend and proj-angularfront with Jasmine or any other Selenium-based frameworks.


#7

I failed to reproduce your recipe.
First of all, I found no documentation on frontendFiles statement. I is strange, but Google gives no results.
Second, I supposed there is framework plugin is used. I have tried to use that in the branch framework-plugin of https://github.com/svok/kotlin-multiplatform-sample. See https://github.com/svok/kotlin-multiplatform-sample/blob/framework-plugin/build.gradle.kts. I did all according to documentation: https://github.com/Kotlin/kotlin-frontend-plugin but the build fails with

Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file '/home/sokatov/workspace-sts/kotlin-multiplatform-sample/build.gradle.kts' line: 20
Plugin [id: 'org.jetbrains.kotlin.frontend'] was not found in any of the following sources: