There are plenty cases when one platform build is to be used in another platform.
For example:
- Use js compiled application in jvm one with webjars
- 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?
What you are trying to accomplish is called Composite Build.
What you refer as “build” is actually a project.
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.
Uhm, could you explain a little more precisely your usecase?
Here GitHub - svok/kotlin-multiplatform-sample: Sample of a backend-frontend bundle with kotlin ktor and different frontends: angular, android, react 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 kotlin-multiplatform-sample/build.gradle.kts at 20513d8d2b3e3126457e221b58406dbea3ecc937 · svok/kotlin-multiplatform-sample · GitHub 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.
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 GitHub - svok/kotlin-multiplatform-sample: Sample of a backend-frontend bundle with kotlin ktor and different frontends: angular, android, react. See https://github.com/svok/kotlin-multiplatform-sample/blob/framework-plugin/build.gradle.kts. I did all according to documentation: GitHub - Kotlin/kotlin-frontend-plugin: Gradle Kotlin (http://kotlinlang.org) plugin for frontend development 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: